Redis - Sorted Set Zrangebylex Command


Advertisements

Redis ZRANGEBYLEX command returns the specified range of elements in the sorted set stored at the key. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with an equal score. Both start and stop are zero-based indexes, where 0 is the first element, 1 is the next element, and so on. They can also be negative numbers indicating offsets from the end of the sorted set, with -1 being the last element of the sorted set, -2 the penultimate element, and so on.

Return Value

Array reply, list of elements in the specified score range.

Syntax

Following is the basic syntax of Redis ZRANGEBYLEX command.

redis 127.0.0.1:6379> ZRANGEBYLEX key min max [LIMIT offset count]

Example

redis 127.0.0.1:6379> ZADD myzset 0 a 0 b 0 c 0 d 0 e 
(integer) 5 
redis 127.0.0.1:6379> ZADD myzset 0 f 0 g 
(integer) 2 
redis 127.0.0.1:6379> ZRANGEBYLEX myzset - [c 
1) "a" 
2) "b" 
3) "c" 
redis 127.0.0.1:6379> ZRANGEBYLEX myzset - (c 
1) "a" 
2) "b"
redis_sorted_sets.htm
Advertisements