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.

ZREVRANGE

Last updated

Deprecated: use ZRANGE instead.

ZREVRANGE key start stop [WITHSCORES]
Group
Sorted set
Complexity
O(log(N)+M) where N is the size of the sorted set and M is the number of members returned
Arity
-4 (at least 4 words, counting the command name)
Flags
read-only
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

ZREVRANGE returns the members of the sorted set at key between positions start and stop, both included, ordered from the highest score to the lowest (ties in reverse lexicographic order). Position 0 is the highest-scored member, and negative positions count from the end. It is the same as ZRANGE key start stop REV; new code can use ZRANGE.

Option Effect
WITHSCORES Return each member with its score. Must be written in all upper case or all lower case.
Case RESP2 RESP3
Success Array of members Same
With WITHSCORES Flat array: member, score, … (scores as bulk strings) Array of [member, score] pairs, the score a double
Key does not exist or empty range Empty array Same

Errors:

  • WRONGTYPE if key holds a value that is not a sorted set.
  • ERR value is not an integer or out of range if start or stop is not an integer.
127.0.0.1:6379> ZADD board 1 "a" 2 "b" 3 "c"
(integer) 3
127.0.0.1:6379> ZREVRANGE board 0 1
1) "c"
2) "b"
127.0.0.1:6379> ZREVRANGE board 0 -1 WITHSCORES
1) "c"
2) "3"
3) "b"
4) "2"
5) "a"
6) "1"

Same replies as Redis 7.4 and Valkey 8 for valid input. Extra or unrecognised trailing arguments are ignored, where Redis and Valkey reply with a syntax error. HotKV also checks the key’s type before start and stop.

ZRANGE, ZREVRANGEBYSCORE, ZREVRANK