ZREVRANGE key start end [WITHSCORES]
Return the specified elements of the sorted set at the specified key.
The elements are considered sorted from the lowerest to the highest score when using ZRANGE, and in the reverse order when using ZREVRANGE.
Start and end are zero-based indexes. 0 is the first element of the sorted set (the one with the lowerest score when using ZRANGE), 1 is the next element by score, and so on.
TIME COMPLEXITY: O(log(N))+O(M) (with N being the number of elements in the sorted set and M the number of elements requested)
Note:
1. start and end can also be negative numbers indicating offsets from the end of the sorted set. For example, -1 is the last element of the sorted set, -2 is the penultimate element, and so on.
2. Indexes out of range will not produce an error: if start is over the end of the sorted set, or start > end, an empty list is returned. If the end is over at the end of the sorted set Redis will threaten it just like the last element of the sorted set.
RETURN VALUE: Multi bulk reply, specifically a list of elements in the specified range.
Syntax:
ZREVRANGE key start end
Example 1: When the key is present and the start and end are in the range.
redis:6379> ZADD mykey 1 A 2 B 3 C 4 D 5 E(integer) 5redis:6379> ZREVRANGE mykey 1 41) "D"2) "C"3) "B"4) "A"
Output
1) "D"
2) "C"
3) "B"
4) "A"
Example 2: When the key is not present or the start and end are in out of range.
redis:6379> ZADD mykey 1 A 2 B 3 C 4 D 5 E(integer) 5redis:6379> ZREVRANGE redisKey 1 4(empty array)redis:6379> ZREVRANGE mykey 10 20(empty array)
Output
empty array
No comments:
Post a Comment