josiahcarlson/redis-in-action

Error in chapter2 ?

yfxie opened this issue · 1 comments

yfxie commented

For both of two lines:
https://github.com/josiahcarlson/redis-in-action/blob/master/python/ch02_listing_source.py#L166
https://github.com/josiahcarlson/redis-in-action/blob/master/python/ch02_listing_source.py#L174

conn.zincrby('viewed:', item, -1) 

It means more views, more negative score.

conn.zremrangebyrank('viewed:', 0, -20001) 

the popular members(with high negative score) will be removed.

see my test:

127.0.0.1:6379> ZADD myset -20 a
(integer) 1
127.0.0.1:6379> ZADD myset -15 b
(integer) 1
127.0.0.1:6379> ZADD myset -10 c
(integer) 1
127.0.0.1:6379> ZADD myset -5 d
(integer) 1
127.0.0.1:6379> ZADD myset -1 e
(integer) 1
127.0.0.1:6379> ZREMRANGEBYRANK myset 0 -3
(integer) 3
127.0.0.1:6379> ZRANGE myset 0 -1 WITHSCORES
1) "d"
2) "-5"
3) "e"
4) "-1"