Redis Zrevrangebyscore Command
Redis Zrevrangebyscore returns all members in a specified score range within a sorted set. The members are ordered by their score values in descending (from largest to smallest) order.
Members with the same score value are ordered in reverse lexicographical order.
Except for the members being ordered by score values in descending order, the ZREVRANGEBYSCORE command is the same as the ZRANGEBYSCORE command.
Syntax
The basic syntax for the redis Zrevrangebyscore command is as follows:
redis 127.0.0.1:6379> ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
Available Versions
= 2.2.0
Return Value
A list of sorted set members within the specified range, with their scores (optional).
Example
redis 127.0.0.1:6379> ZADD salary 10086 jack
(integer) 1
redis > ZADD salary 5000 tom
(integer) 1
redis 127.0.0.1:6379> ZADD salary 7500 peter
(integer) 1
redis 127.0.0.1:6379> ZADD salary 3500 joe
(integer) 1
redis 127.0.0.1:6379> ZREVRANGEBYSCORE salary +inf -inf # Reverse order of all members
1) "jack"
2) "peter"
3) "tom"
4) "joe"
redis 127.0.0.1:6379> ZREVRANGEBYSCORE salary 10000 2000 # Reverse order of members with salaries between 10000 and 2000
1) "peter"
2) "tom"
3) "joe"