Easy Tutorial
❮ Sets Scard Strings Decrby ❯

Redis Zrevrank Command

Redis Sorted Set

The Redis Zrevrank command returns the rank of a member in the sorted set. The sorted set members are ordered by their score values in descending (from largest to smallest) order.

The rank is zero-based, meaning the member with the highest score has a rank of 0.

The ZRANK command can be used to get the rank of a member ordered by score values in ascending (from smallest to largest) order.

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, it returns the rank of the member. If the member is not a member of the sorted set key, it returns nil.

Example

redis 127.0.0.1:6379> ZRANGE salary 0 -1 WITHSCORES     # Test data
1) "jack"
2) "2000"
3) "peter"
4) "3500"
5) "tom"
6) "5000"

redis 127.0.0.1:6379> ZREVRANK salary peter     # Peter's salary is second
(integer) 1

redis 127.0.0.1:6379> ZREVRANK salary tom       # Tom's salary is the highest
(integer) 0

Redis Sorted Set

❮ Sets Scard Strings Decrby ❯