Redis - Sorted Set Zrangebyscore Command


Redis ZRANGEBYSCORE command returns all the elements in the sorted set at the key with a score between min and max (including elements with score equal to min or max). The elements are considered to be ordered from low to high scores. The elements having the same score are returned in lexicographical order (this follows from a property of the sorted set implementation in Redis and does not involve further computation).

Return Value

Array reply, list of elements in the specified score range (optionally with their scores).


Following is the basic syntax of Redis ZRANGEBYSCORE command.

redis> ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]


redis> ZADD myzset 0 a 1 b 2 c 3 d 4 e 
(integer) 5 
redis> ZADD myzset 5 f 6 g 
(integer) 2 
redis> ZRANGEBYSCORE myzset 1 2 
1) "b" 
2) "c" 
redis> ZRANGEBYSCORE myzset (1 2 
1) "b" 

Useful Video Courses


Redis and PHP

22 Lectures 40 mins