Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

ZREVRANK

Last updated
ZREVRANK 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

ZREVRANK returns the position of member in the sorted set at key, ordered from the highest score to the lowest. The highest-scored member has rank 0. It is the mirror of ZRANK.

Option Effect
WITHSCORE Also return the member’s score.
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 error if the third argument is not WITHSCORE.
  • WRONGTYPE if key holds a value that is not a sorted set.
127.0.0.1:6379> ZADD board 100 "alice" 90 "bob" 95 "carol"
(integer) 3
127.0.0.1:6379> ZREVRANK board "alice"
(integer) 0
127.0.0.1:6379> ZREVRANK board "bob" WITHSCORE
1) (integer) 2
2) "90"

Same as Redis 7.4 and Valkey 8.

ZRANK, ZSCORE, ZREVRANGE