zrangebyscore
ZRANGEBYSCORE
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Query members in a score range
Usage: zrangebyscore key min max.
min and max are the score range, and the query is inclusive.
Use -inf, +inf to query all members.
Use withscores to also return scores.
Example
| Command> | zadd mycom 2009 "Sun microsystems" 1992 Wang 2002 Netscape |
| Result> | 3 |
| Command> | zadd mycom 1998 "Digital Equipment" 2002 K-mart 1987 "American motors" |
| Result> | 3 |
| Command> | zrangebyscore mycom -inf +inf withscores |
| Result> |
0) 1987 -> American motors 1) 1992 -> Wang 2) 1998 -> Digital Equipment 3) 2002 -> K-mart If scores are equal, members are compared 4) 2002 -> Netscape 5) 2009 -> Sun microsystems |
| Command> | zrangebyscore mycom 1998 2002 withscores |
| Result> |
0) 1998 -> Digital Equipment 1) 2002 -> K-mart 2) 2002 -> Netscape |
| Command> | zrangebyscore mycom 2005 +inf withscores |
| Result> | 0) 2009 -> Sun microsystems |
Use ( on min/max for exclusive bounds
Usage: zrangebyscore key (min (max.
Example
| Command> | zrangebyscore mycom (1987 (2002 withscores |
| Result> |
0) 1992 -> Wang 1) 1998 -> Digital Equipment |
| Command> | zrangebyscore mycom (1998 2002 withscores 1998 < score <= 2002 |
| Result> |
0) 2002 -> K-mart 1) 2002 -> Netscape |
Using limit offset count
Usage: zrangebyscore key min max limit offset count.
offset is the starting point, and count is the number of members to return.
offset can start from 0, and count must be 1 or greater. If count is 0, nothing is returned.
If limit is used, both offset and count are required and cannot be omitted.
Useful for paging.
Example
| Command> | zrangebyscore mycom -inf +inf withscores limit 0 3 |
| Result> |
0) 1987 -> American motors 1) 1992 -> Wang 2) 1998 -> Digital Equipment |
| Command> | zrangebyscore mycom -inf +inf withscores limit 3 100 |
| Result> |
0) 2002 -> K-mart 1) 2002 -> Netscape 2) 2009 -> Sun microsystems |
Syntax
ZRANGEBYSCORE key min max [withscores] [limit offset count]
- Available since version 1.2.0.
- The withscores option is available since version 2.0.0.
- Time complexity is O(log(N)+M). N is the number of members in the set, and, M is the number of members returned.
| Related commands | ZRANGE, ZREVRANGE, ZREVRANGEBYSCORE, LRANGE |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << ZREVRANGE | ZRANGEBYSCORE | ZREVRANGEBYSCORE >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
