Redis - Sorted Set Zrevrangebyscore Command

Redis ZREVRANGEBYSCORE command returns all the elements in the sorted set at the key with a score between max and min (including elements with score equal to max or min). In contrary to the default ordering of sorted sets, for this command the elements are considered to be ordered from high to low scores. The elements having the same score are returned in a reverse lexicographical order

Return Value

Array reply, list of elements in the specified score range (optionally with their scores).


Following is the basic syntax of Redis ZREVRANGEBYSCORE command.

redis> ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]


redis> ZADD myzset 1 b 2 c 3 d 4 e 
(integer) 4 
redis> ZREVRANGEBYSCORE myzset +inf -inf 
1) "e" 
2) "d" 
3) "c" 
4) "b" 
redis> ZREVRANGEBYSCORE myzset 2 1 
1) "c" 
2) "b"