Redis Sorted Sets: ZREVRANGEBYSCORE
ZREVRANGEBYSCORE key max min [WITHSCORES]
Redis ZREVRANGEBYSCORE command is used to return all the elements in the sorted set at the key with a score between maximum and minimum values. 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 reverse lexicographical order.
Syntax:
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
Return Value
Array reply, a list of elements in the specified score range (optionally with their scores).
Example: Redis ZREVRANGEBYSCORE
127.0.0.1:6379> ZADD mysales 1556 Samsung 2000 Nokis 1800 Micromax (integer) 3 127.0.0.1:6379> ZADD mysales 2200 Sunsui 1800 MicroSoft 2500 LG (integer) 3 127.0.0.1:6379> ZREVRANGEBYSCORE mysales +inf -inf WITHSCORES 1) "LG" 2) "2500" 3) "Sunsui" 4) "2200" 5) "Nokis" 6) "2000" 7) "Micromax" 8) "1800" 9) "MicroSoft" 10) "1800" 11) "Samsung" 12) "1556" 127.0.0.1:6379> ZREVRANGEBYSCORE mysales 2000 1800 WITHSCORES 1) "Nokis" 2) "2000" 3) "Micromax" 4) "1800" 5) "MicroSoft" 6) "1800" 127.0.0.1:6379> ZREVRANGEBYSCORE mysales +inf 2200 WITHSCORES 1) "LG" 2) "2500" 3) "Sunsui" 4) "2200"
Example: Redis ZREVRANGEBYSCORE: Using '(' to the max, min
127.0.0.1:6379> ZADD mysales 1556 Samsung 2000 Nokis 1800 Micromax (integer) 3 127.0.0.1:6379> ZADD mysales 2200 Sunsui 1800 MicroSoft 2500 LG (integer) 3 127.0.0.1:6379> ZREVRANGEBYSCORE mysales +inf -inf WITHSCORES 1) "LG" 2) "2500" 3) "Sunsui" 4) "2200" 5) "Nokis" 6) "2000" 7) "Micromax" 8) "1800" 9) "MicroSoft" 10) "1800" 11) "Samsung" 12) "1556" 127.0.0.1:6379> ZREVRANGEBYSCORE mysales (2100 (1800 WITHSCORES 1) "Nokis" 2) "2000" 127.0.0.1:6379> ZREVRANGEBYSCORE mysales 2100 (1800 WITHSCORES 1) "Nokis" 2) "2000"
Example: Redis ZREVRANGEBYSCORE: Use limit offset count
127.0.0.1:6379> ZADD mysales 1556 Samsung 2000 Nokis 1800 Micromax (integer) 3 127.0.0.1:6379> ZADD mysales 2200 Sunsui 1800 MicroSoft 2500 LG (integer) 3 127.0.0.1:6379> ZREVRANGEBYSCORE mysales +inf -inf WITHSCORES 1) "LG" 2) "2500" 3) "Sunsui" 4) "2200" 5) "Nokis" 6) "2000" 7) "Micromax" 8) "1800" 9) "MicroSoft" 10) "1800" 11) "Samsung" 12) "1556" 127.0.0.1:6379> ZREVRANGEBYSCORE mysales +inf -inf WITHSCORES LIMIT 0 3 1) "LG" 2) "2500" 3) "Sunsui" 4) "2200" 5) "Nokis" 6) "2000" 127.0.0.1:6379> ZREVRANGEBYSCORE mysales +inf -inf WITHSCORES LIMIT 3 10 1) "Micromax" 2) "1800" 3) "MicroSoft" 4) "1800" 5) "Samsung" 6) "1556"
Previous:
ZREVRANGEBYLEX
Next:
ZREVRANK
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics