Sunday 12 April 2015

ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]

Syntax
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
    Returns all the elements in the sorted set, where the score is in between min and max. The elements are ordered from highest to lowest scores.

127.0.0.1:6379> zadd set1 1 one 2 two 3 three 4 four 5 five 
(integer) 5 
127.0.0.1:6379> zadd set1 1 six 2 seven 3 eight 4 nine 5 ten 
(integer) 5 
127.0.0.1:6379> zadd set1 1 eleven 2 twelve 3 thirteen 4 fourteen 5 fifteen 
(integer) 5
127.0.0.1:6379> zrevrangebyscore set1 5 2 
 1) "ten" 
 2) "five" 
 3) "fifteen" 
 4) "nine" 
 5) "fourteen" 
 6) "four" 
 7) "three" 
 8) "thirteen" 
 9) "eight" 
10) "two" 
11) "twelve" 
12) "seven" 


The WITHSCORES argument return both the element and its score.

127.0.0.1:6379> zrevrangebyscore set1 5 2 withscores 
 1) "ten" 
 2) "5" 
 3) "five" 
 4) "5" 
 5) "fifteen" 
 6) "5" 
 7) "nine" 
 8) "4" 
 9) "fourteen" 
10) "4" 
11) "four" 
12) "4" 
13) "three" 
14) "3" 
15) "thirteen" 
16) "3" 
17) "eight" 
18) "3" 
19) "two" 
20) "2" 
21) "twelve" 
22) "2" 
23) "seven" 
24) "2" 


count and offset are used to get subset of results.

if you want the first 5 results, count = 5, offset = 0
if you want the results 10 to 15, count = 5, offset = 10
127.0.0.1:6379> zrevrangebyscore set1 5 2 limit 0 5 
1) "ten" 
2) "five" 
3) "fifteen" 
4) "nine" 
5) "fourteen" 
127.0.0.1:6379> zrevrangebyscore set1 5 2 limit 5  5 
1) "four" 
2) "three" 
3) "thirteen" 
4) "eight" 
5) "two" 
127.0.0.1:6379> zrevrangebyscore set1 5 2 limit 10 5 
1) "twelve" 
2) "seven" 


 
Prevoius                                                 Next                                                 Home

No comments:

Post a Comment