Latest web development tutorials

Redis Zrangebyscore command

Redis ordered set (sorted set)

Redis Zrangebyscore returns a list of the members of an ordered collection at the specified score range. Ordered set by a member of fractional increments (small to large) order of.

Members have the same point value according to lexicographic order (the property is set to provide an orderly and does not require additional calculations).

By default, the range of values ​​using the closed interval (less than or equal to greater than or equal), you can also increase to the former parameters (symbol using the optional open interval (less than or greater than).

for example:

ZRANGEBYSCORE zset (1 5

Back to all qualifying 1 <score <= 5 members, and

ZRANGEBYSCORE zset (5 (10

Returns all eligible members of the 5 <score <10 in.

grammar

redis Zrangebyscore basic command syntax is as follows:

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

Available versions

> = 1.0.5

return value

Within a specified range, the list of members of the ordered sets with fractional value (optional) in.

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"

Redis ordered set (sorted set)