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).

Syntax

Following is the basic syntax of Redis ZREVRANGEBYSCORE command.

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

Example

redis 127.0.0.1:6379> ZADD myzset 1 b 2 c 3 d 4 e 
(integer) 4 
redis 127.0.0.1:6379> ZREVRANGEBYSCORE myzset +inf -inf 
1) "e" 
2) "d" 
3) "c" 
4) "b" 
redis 127.0.0.1:6379> ZREVRANGEBYSCORE myzset 2 1 
1) "c" 
2) "b"
redis_sorted_sets.htm
Advertisements