Sunday, 12 April 2015

ZRANGE key start stop [WITHSCORES]


Syntax
ZRANGE key start stop [WITHSCORES]
    Returns the specified range of elements from given sorted set. The elements are returned from sorted set based on their scores from ascending to descending.
127.0.0.1:6379> zadd set1 1 India 5 America 3 China 
(integer) 3 
127.0.0.1:6379> zrange set1 0 1 
1) "India" 
2) "China" 
127.0.0.1:6379> zrange set1 0 1 withscores 
1) "India" 
2) "1" 
3) "China" 
4) "3" 


If start is larger than the size of the sorted set or start > stop, an empty list is returned.

127.0.0.1:6379> zrange set1 2 1 withscores 
(empty list or set) 
127.0.0.1:6379> zrange set1 3 5 withscores 
(empty list or set) 

start and stop can take -ve values also, -1 represents the last element in the sorted set etc.,
 
127.0.0.1:6379> zrange set1 -3 -1 withscores 
1) "India" 
2) "1" 
3) "China" 
4) "3" 
5) "America" 
6) "5" 



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment