ZREVRANGEBYSCORE

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Query members in a score range in reverse order

Usage: zrevrangebyscore key max min.
max and min are the score range, and the query is inclusive.
Use +inf, -inf to query all members.
Compared with zrangebyscore, results are returned from the highest score, and max comes first.
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>zrevrangebyscore mycom +inf -inf withscores
Result> 0) 2009 -> Sun microsystems
1) 2002 -> Netscape
2) 2002 -> K-mart
3) 1998 -> Digital Equipment
4) 1992 -> Wang
5) 1987 -> American motors
Command>zrevrangebyscore mycom 2002 1998 withscores
Result> 0) 2002 -> Netscape
1) 2002 -> K-mart
2) 1998 -> Digital Equipment
Command>zrevrangebyscore mycom +inf 2005 withscores
Result> 0) 2009 -> Sun microsystems

View animation


Use ( on max/min for exclusive bounds

Usage: zrangebyscore key (max (min.

Example

Command>zrevrangebyscore mycom (2002 (1987 withscores    2002 > score > 1987
Result> 0) 1998 -> Digital Equipment
1) 1992 -> Wang
Command>zrevrangebyscore mycom 2002 (1998 withscores    2002 >= score > 1998
Result> 0) 2002 -> Netscape
1) 2002 -> K-mart

View animation


Using limit offset count

Usage: zrangebyscore key max min limit offset count.
offset is the starting point, and count is the number of members to return.
offset starts 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>zrevrangebyscore mycom +inf -inf withscores limit 0 3
Result> 0) 2009 -> Sun microsystems
1) 2002 -> Netscape
2) 2002 -> K-mart
Command>zrevrangebyscore mycom +inf -inf withscores limit 3 100
Result> 0) 1998 -> Digital Equipment
1) 1992 -> Wang
2) 1987 -> American motors

View animation



Syntax

ZREVRANGEBYSCORE key max min [withscores] [limit offset count]

  • Available since version 2.2.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

<< ZRANGEBYSCORE ZREVRANGEBYSCORE ZRANGEBYLEX >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.