ZREVRANGE

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

Query the member list (from highest score)

Usage: zrevrange key start stop.
start stop are indexes. In zrange index 0 is the lowest score, but in REV index 0 is the highest score.
Members are returned from highest score. If scores are equal, members are compared.
Use 0 -1 to query all members.

Example

Command>zadd myzip 9926 "Seoul" 3426 "Busan" 2465 "Daegu" 2826 "Incheon" 1514 "Gwangju" 12137 "Gyeonggi"
Result>6
Command>zrevrange myzip 0 -1 withscores   Shown from highest score
Result> 0) 12137 -> Gyeonggi
1) 9926 -> Seoul
2) 3426 -> Busan
3) 2826 -> Incheon
4) 2465 -> Daegu
5) 1514 -> Gwangju
The data above is 2013 population by city/province (unit: thousands).

Range query

Example

Command>zrevrange myzip 0 1 withscores    Query the 2 most populous cities/provinces
Result> 0) 12137 -> Gyeonggi
1) 9926 -> Seoul
Command>zrevrange myzip -2 -1 withscores    Query the 2 least populous cities/provinces
Result> -2) 2465 -> Daegu
-1) 1514 -> Gwangju

View animation



Syntax

ZREVRANGE key start stop [withscores]

  • Available since version 1.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, LRANGE
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< ZLS ZREVRANGE ZRANGEBYSCORE >>

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