Redis - Sorted Set Zrangebylex Command


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.


Following is the basic syntax of Redis ZRANGEBYLEX command.

redis> ZRANGEBYLEX key min max [LIMIT offset count]


redis> ZADD myzset 0 a 0 b 0 c 0 d 0 e 
(integer) 5 
redis> ZADD myzset 0 f 0 g 
(integer) 2 
redis> ZRANGEBYLEX myzset - [c 
1) "a" 
2) "b" 
3) "c" 
redis> ZRANGEBYLEX myzset - (c 
1) "a" 
2) "b"

Useful Video Courses


Redis and PHP

22 Lectures 40 mins