ZREVRANGEBYSCORE command in redis

ZREVRANGEBYSCORE key max min [WITHSCORES]

Returns a range of members in a sorted set, by score, with scores ordered from high to low.

Redis ZREVRANGEBYSCORE command returns all the elements in the sorted set at the key with a score between max and min (including elements with a score equal to max or min).

Note:

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:

ZREVRANGEBYSCORE key max min [WITHSCORES]

Example 1: WITHOUT SCORE

redis:6379> ZADD mykey 0 A 2 C 3 D 1 E
(integer) 4
redis:6379> ZREVRANGEBYSCORE mykey 3 1
1) "D"
2) "C"
3) "E"


Example 2: WITHSCORES

redis:6379> ZADD mykey 0 A 2 C 3 D 1 E
(integer) 4
redis:6379> ZREVRANGEBYSCORE mykey 3 1 WITHSCORES
1) "D"
2) "3"
3) "C"
4) "2"
5) "E"
6) "1"


No comments:

Post a Comment