Redis Sorted Sets: ZRANK
Redis ZRANK Command
Redis ZRANK command is used to return the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank is 0-based, which means that the member with the lowest score has rank 0.
Here are some common uses and scenarios for the "ZRANK" command:
- Leaderboards: Find the rank of a player based on their score in a leaderboard.
- Ranking Systems: Retrieve the position/rank of a member based on their score.
- Performance Comparison: Compare the performance of members relative to each other based on their scores.
- Data Analysis: Analyze data by determining the relative position of members within a sorted set.
- Score Thresholds: Monitor members based on their position relative to score thresholds.
Syntax:
ZRANK 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 the member does not exist in the sorted set or key does not exist, Bulk string reply, nil.
Return Value Type
Integer
Example: Redis ZRANK
127.0.0.1:6379> ZADD mysales 1556 Samsung 2000 Nokia 1800 Micromax (integer) 3 127.0.0.1:6379> ZADD mysales 2200 Sunsui 1800 MicroSoft 2500 LG (integer) 3 127.0.0.1:6379> ZRANGE mysales 0 -1 WITHSCORES 1) "Samsung" 2) "1556" 3) "MicroSoft" 4) "1800" 5) "Micromax" 6) "1800" 7) "Nokia" 8) "2000" 9) "Sunsui" 10) "2200" 11) "LG" 12) "2500" 127.0.0.1:6379> ZRANGE mysales 0 -1 WITHSCORES 1) "Samsung" 2) "1556" 3) "MicroSoft" 4) "1800" 5) "Micromax" 6) "1800" 7) "Nokia" 8) "2000" 9) "Sunsui" 10) "2200" 11) "LG" 12) "2500" 127.0.0.1:6379> ZRANK mysales "Sunsui" (integer) 4 127.0.0.1:6379> ZRANK mysales MicroSoft (integer) 1
Previous:
ZRANGEBYSCORE
Next:
ZREM
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://www.w3resource.com/redis/redis-zrank-key-member.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics