English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Zrangebyscore Command

Redis Sorted Sets (sorted set)

Redis Zrangebyscore returns a list of members in the specified score range of the ordered set. The members of the ordered set are sorted in ascending order of score value (from small to large).

Members with the same score value are sorted in dictionary order (this property is provided by the ordered set and does not require additional calculation).

By default, the value range of the interval uses a closed interval (less than or equal to or greater than or equal to), and you can also use an optional open interval (less than or greater than) by adding the ( symbol before the parameter.

Take an example:

ZRANGEBYSCORE zset (1 5

Return all matching conditions 1 < score <= 5 members, while

ZRANGEBYSCORE zset (5 (10

Then return all members that meet the conditions 5 < score < 10 members.

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

List of sorted set members within a specified range, with optional score values.

Online Examples

redis 127.0.0.1:6379> ZADD salary 2500 jack                       # Test data
(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               # Display the entire sorted set
1) "jack"
2) "tom"
3) "peter"
redis 127.0.0.1:6379> ZRANGEBYSCORE salary -inf +inf WITHSCORES    # Display the entire sorted set and member's score value
1) "jack"
2) ""2500"
3) "tom"
4) ""5000"
5) "peter"
6) ""12000"
redis 127.0.0.1:6379> ZRANGEBYSCORE salary -inf 5000 WITHSCORES    # Display salary <=5000 all members
1) "jack"
2) ""2500"
3) "tom"
4) ""5000"
redis 127.0.0.1:6379> ZRANGEBYSCORE salary (5000 400000             # Display salaries greater than 5000 less than or equal to 400000 member
1) "peter"

Redis Sorted Sets (sorted set)