Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

ZREVRANGEBYLEX

Last updated

Deprecated: use ZRANGE instead.

ZREVRANGEBYLEX key max min [LIMIT offset count]
Group
Sorted set
Complexity
O(log(N)+M) where N is the size of the sorted set and M is the number of members returned
Arity
-4 (at least 4 words, counting the command name)
Flags
read-only
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

ZREVRANGEBYLEX returns the members of the sorted set at key that fall between max and min in byte-wise lexicographic order, largest first. Note that the higher bound comes first. It is the same as ZRANGE key max min BYLEX REV; new code can use ZRANGE.

Each bound must be [value (inclusive), (value (exclusive), - or +.

Option Effect
LIMIT offset count Skip offset matching members, then return at most count. A negative count returns all remaining members.
Case RESP2 RESP3
Success Array of members Same
Key does not exist or nothing in range Empty array Same

Errors are the same as for ZRANGEBYLEX.

127.0.0.1:6379> ZADD names 0 "ann" 0 "bob" 0 "cat" 0 "dan"
(integer) 4
127.0.0.1:6379> ZREVRANGEBYLEX names (d [b
1) "cat"
2) "bob"
127.0.0.1:6379> ZREVRANGEBYLEX names + - LIMIT 0 1
1) "dan"

Same as Redis 7.4 and Valkey 8, where it is also deprecated in favour of ZRANGE ... BYLEX REV.

ZRANGE, ZRANGEBYLEX, ZLEXCOUNT