Redis – Sorted Set Zrangebyscore Command

  • Post author:
  • Post category:Redis
  • Post comments:2 Comments

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).

Syntax

Following is the basic syntax of Redis ZRANGEBYSCORE command.

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

Example

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

This Post Has 2 Comments

Leave a Reply