Redis Zrevrank Command

Redis Sorted Set

The Redis Zrevrank command returns the rank of a member in a sorted set, with members ordered by score decreasing (from high to low).

Ranks are zero-based, meaning the member with the highest score has rank 0.

Use the ZRANK command to obtain the rank of members ordered by score increasing (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 Versions

>= 2.2.0

Return Value

If the member is a member of the sorted set key, the rank of the member is returned. If the member is not a member of the sorted set key, nil is returned.

Examples

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

Redis Sorted Set

Other Extensions