Redis Zrangebyscore command
Redis Zrangebyscore returns the list of members in the sorted set within the specified score interval. The sorted set members are arranged in increasing order of score value (from small to large).
Members with the same score value are arranged in lexicographical order (this property is provided by the sorted set and does not require additional calculation).
By default, the interval uses closed intervals (less than or equal to or greater than or equal to). You can also use an optional open interval (less than or greater than) by adding the ( symbol before the parameter.
For example:
ZRANGEBYSCORE zset (1 5
Returns all members satisfying 1 < score <= 5, and
ZRANGEBYSCORE zset (5 (10
returns all members satisfying 5 < score < 10.
Syntax
The basic syntax of the redis Zrangebyscore command is as follows:
redis 127.0.0.1:6379> ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
Available versions
>= 1.0.5
Return value
A list of sorted set members with score values (optional) within the specified interval.
Examples
redis 127.0.0.1:6379> ZADD salary 2500 jack # 测试数据 (integer) 0 redis 127.0.0.1:6379> ZADD salary 5000 tom (integer) 0 redis 127.0.0.1:6379> ZADD salary 12000 peter (integer) 0 redis 127.0.0.1:6379> ZRANGEBYSCORE salary -inf +inf # 显示整个有序集 1) "jack" 2) "tom" 3) "peter" redis 127.0.0.1:6379> ZRANGEBYSCORE salary -inf +inf WITHSCORES # 显示整个有序集及成员的 score 值 1) "jack" 2) "2500" 3) "tom" 4) "5000" 5) "peter" 6) "12000" redis 127.0.0.1:6379> ZRANGEBYSCORE salary -inf 5000 WITHSCORES # 显示工资 <=5000 的所有成员 1) "jack" 2) "2500" 3) "tom" 4) "5000" redis 127.0.0.1:6379> ZRANGEBYSCORE salary (5000 400000 # 显示工资大于 5000 小于等于 400000 的成员 1) "peter"
Other extensions
