Redis Zrangebyscore Command
Redis Tutorial
Redis Commands
Advanced Redis Tutorials
Explore Deeper
- Programming
- Scripting
- Scripting Languages
- Data Management
- Network Services
- Web Service
- Search
- Computer Science
- Development Tools
- Network Design and Development
Redis Zrangebyscore Command
The Redis ZRANGEBYSCORE command returns a list of members from a sorted set within a specified score range. Members in the sorted set are ordered by their score values in ascending order (from small to large).
Members with the same score value are ordered lexicographically (this property is provided by the sorted set and does not require additional computation).
By default, interval values use closed intervals (less than or equal to, greater than or equal to). You can also use optional open intervals (less than or greater than) by adding a ( symbol before the parameter.
For example:
ZRANGEBYSCORE zset (1 5
Returns all members satisfying 1 < score <= 5, while:
ZRANGEBYSCORE zset (5 (10
Returns all members satisfying 5 < score < 10.
Syntax
The basic syntax for the Redis ZRANGEBYSCORE command is as follows:
redis 127.0.0.1:6379> ZRANGEBYSCORE key min max
Available Version
>= 1.0.5
Return Value
A list of sorted set members within the specified range, optionally including their score values.
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 entire sorted set
1) "jack"
2) "tom"
3) "peter"
redis 127.0.0.1:6379> ZRANGEBYSCORE salary -inf +inf WITHSCORES # Display entire sorted set and member scores
1) "jack"
2) "2500"
3) "tom"
4) "5000"
5) "peter"
6) "12000"
redis 127.0.0.1:6379> ZRANGEBYSCORE salary -inf 5000 WITHSCORES # Display salaries
YouTip