开发者

about zrank command in redis

ZRANK returns the rank of the member in the sorted set, with scores ordered from low开发者_如何学编程 to high. ZREVRANK returns the rank with scores ordered from high to low. When the given member does not exist in the sorted set, the special value 'nil' is returned. The returned rank (or index) of the member is 0-based for both commands.

what does the 'with scores ordered from low to high. ZREVRANK returns the rank with scores ordered from high to low' meaning? in my mind, the ZRANK will get the member's score. why the pharse said orderd from low to high?


The important thing here is that ZRANK returns the zero-based index of the member, not it's score at all. Thus, "scores ordered from low to high" or "scores ordered from high to low" is just to provide a reference for what "direction" the sorted set is being read.

Consider this:

redis> zadd foo 0 a
(integer) 1
redis> zadd foo 1 b
(integer) 1
redis> zadd foo 2 c
(integer) 1
redis> zrank foo c
(integer) 2
redis> zrevrank foo c
(integer) 0

Note that the rank of c is 2 when being read from "scores low to high" but it's revrank is 0 when being read from "scores high to low"


The commands are much the same, with the "REV" being for "reversed".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜