Redis Zrevrank command
The Redis Zrevrank command returns the rank of a member in a sorted set. Members are ordered by descending score value (from high to low).
Ranking is 0-based, meaning the member with the highest score has rank 0.
Using the ZRANK command returns the rank of the member ordered by ascending score value (from low to high).
Syntax
The basic syntax of the redis Zrevrank command is as follows:
redis 127.0.0.1:6379> ZREVRANK key member
Available Version
= 2.2.0
Return Value
If the member is a member of the sorted set key, returns the rank of the member. If the member is not a member of the sorted set key, returns nil.
Example
redis 127.0.0.1:6379> ZRANGE salary 0 -1 WITHSCORES # 测试数据
1) "jack"
2) "2000"
3) "peter"
4) "3500"
5) "tom"
6) "5000"
redis 127.0.0.1:6379> ZREVRANK salary peter # peter 的工资排第二
(integer) 1
redis 127.0.0.1:6379> ZREVRANK salary tom # tom 的工资最高
(integer) 0
