ZRANK
ZRANK key member [WITHSCORE]
- Group
- Sorted set
- Complexity
- O(log(N)) where N is the size of the sorted set
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- read-only, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
ZRANK returns the position of member in the sorted set at key, ordered
from the lowest score to the highest. The lowest-scored member has rank 0.
For the rank from the highest score down, use ZREVRANK.
Options
Section titled “Options”| Option | Effect |
|---|---|
WITHSCORE |
Also return the member’s score. |
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Member exists | Integer: the rank | Same |
Member exists, with WITHSCORE |
Two-element array: the rank (integer) and the score (bulk string) | Two-element array: the rank (integer) and the score (double) |
| Member or key does not exist | Nil bulk string | Null |
Member or key does not exist, with WITHSCORE |
Nil array | Null |
Errors:
ERR syntax errorif the third argument is notWITHSCORE.WRONGTYPEifkeyholds a value that is not a sorted set.
Examples
Section titled “Examples”127.0.0.1:6379> ZADD board 100 "alice" 90 "bob" 95 "carol"(integer) 3127.0.0.1:6379> ZRANK board "carol"(integer) 1127.0.0.1:6379> ZRANK board "alice" WITHSCORE1) (integer) 22) "100"127.0.0.1:6379> ZRANK board "nobody"(nil)Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.