w3resource

Redis Sorted Sets: ZREVRANK

Redis ZREVRANK Command

Redis ZREVRANK command is used to return the rank of member in the sorted set stored at key, with the scores ordered from high to low. The rank is 0-based, which means that the member with the highest score has rank 0.

Here are some common uses and scenarios for the "ZREVRANK" command:

  • Descending Rank Queries: Find the rank of a member based on scores in descending order.
  • Leaderboards: Determine the position of a player within a leaderboard sorted by descending scores.
  • Ranking Systems: Retrieve the reverse rank of a member for various ranking applications.
  • Performance Comparison: Compare the performance of members by their descending order rank.
  • Data Analysis: Analyze the relative position of members within a sorted set when ranked from highest to lowest scores.

Syntax:

ZREVRANK key member

Available since

2.0.0.

Return Value

  • If a member exists in the sorted set, Integer reply: the rank of the member.
  • If a member does not exist in the sorted set or key does not exist, Bulk string reply: nil.

Return Value Type

Integer

Example: Redis ZREVRANK

127.0.0.1:6379> ZADD mycityset 80 Delhi 60 Mumbai 70 Hyderabad 50 Kolkata 65 Chennai
(integer) 5
127.0.0.1:6379> ZREVRANGE mycityset 0 -1 WITHSCORES
 1) "Delhi"
 2) "80"
 3) "Hyderabad"
 4) "70"
 5) "Chennai"
 6) "65"
 7) "Mumbai"
 8) "60"
 9) "Kolkata"
10) "50"
127.0.0.1:6379> ZREVRANK mycityset Hyderabad
(integer) 1
127.0.0.1:6379> ZREVRANK mycityset Kolkata
(integer) 4

Previous: ZREVRANGEBYSCORE
Next: ZSCORE



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/redis/redis-zrevrank-key-member.php