zrevrangebyscore.3valkey - Man Page

Returns members in a sorted set within a range of scores in reverse order.

Synopsis

ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]

Description

Returns all the elements in the sorted set at 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 reverse lexicographical order.

Apart from the reversed ordering, ZREVRANGEBYSCORE is similar to ZRANGEBYSCORE.

Reply

Complexity

O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).

Acl Categories

@read @slow @sortedset

History

Notes

This command is deprecated (since 6.2.0) and replaced by ZRANGE with the REV and BYSCORE arguments.

Examples

127.0.0.1:6379> ZADD myzset 1 "one"
(integer) 1
127.0.0.1:6379> ZADD myzset 2 "two"
(integer) 1
127.0.0.1:6379> ZADD myzset 3 "three"
(integer) 1
127.0.0.1:6379> ZREVRANGEBYSCORE myzset +inf -inf
1) "three"
2) "two"
3) "one"
127.0.0.1:6379> ZREVRANGEBYSCORE myzset 2 1
1) "two"
2) "one"
127.0.0.1:6379> ZREVRANGEBYSCORE myzset 2 (1
1) "two"
127.0.0.1:6379> ZREVRANGEBYSCORE myzset (2 (1
(empty array)

See Also

bzmpop(3valkey), bzpopmax(3valkey), bzpopmin(3valkey), zadd(3valkey), zcard(3valkey), zcount(3valkey), zdiff(3valkey), zdiffstore(3valkey), zincrby(3valkey), zinter(3valkey), zintercard(3valkey), zinterstore(3valkey), zlexcount(3valkey), zmpop(3valkey), zmscore(3valkey), zpopmax(3valkey), zpopmin(3valkey), zrandmember(3valkey), zrange(3valkey), zrangestore(3valkey), zrank(3valkey), zrem(3valkey), zremrangebylex(3valkey), zremrangebyrank(3valkey), zremrangebyscore(3valkey), zrevrank(3valkey), zscan(3valkey), zscore(3valkey), zunion(3valkey), zunionstore(3valkey)

Info

2024-09-23 8.0.0 Valkey Command Manual