Redis Sorted Sets: ZRANGE
ZRANGE key start stop [WITHSCORES]
Redis ZRANGE command is used to return the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with equal score.
Both start and stop are zero-based indexes,
- 0 is the first element,
- 1 is the next element and so on.
They can also be negative numbers indicating offsets from the end of the sorted set,
- -1 being the last element of the sorted set
- -2 the penultimate element and so on.
Syntax:
ZRANGE KEY START STOP [WITHSCORES]
Available since
1.2.0.
Return Value
Array reply, a list of elements in the specified range (optionally with their scores).
Return Value Type
Array
Example: Redis ZRANGE
127.0.0.1:6379> ZADD mycity 1 Delhi 2 London 3 Paris 4 Tokyo 5 NewYork 6 Seoul (integer) 6 127.0.0.1:6379> ZRANGE mycity 0 -1 1) "Delhi" 2) "London" 3) "Paris" 4) "Tokyo" 5) "NewYork" 6) "Seoul" 127.0.0.1:6379> ZRANGE mycity 0 -1 WITHSCORES 1) "Delhi" 2) "1" 3) "London" 4) "2" 5) "Paris" 6) "3" 7) "Tokyo" 8) "4" 9) "NewYork" 10) "5" 11) "Seoul" 12) "6"
Previous:
ZLEXCOUNT
Next:
ZRANGEBYLEX
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics