AttentionThis page documents an earlier version. Go to the latest (v2.1)version.
ZRANGE key start stop [WITHSCORES]
This command returns
members ordered from lowest to highest score in the specified range at sorted set
stop represent the low and high index bounds respectively and are zero-indexed. They can also be negative
numbers indicating offsets from the end of the sorted set, with -1 being the last element of the sorted set, -2 the penultimate element, and so on.
key does not exist, an empty list is returned. If
key is associated with non sorted-set data, an error is returned.
Returns a list of members found in the range specified by
stop, unless the WITHSCORES option is specified (see below).
You can do this as shown below.
$ ZADD z_key 1.0 v1 2.0 v2 3.0 v3
$ ZRANGE z_key 0 2
1) "v1" 2) "v2" 3) "v3"
With negative indices.
$ ZRANGE z_key -2 -1
1) "v2" 2) "v3"
Both positive and negative indices.
$ ZRANGE z_key 1 -1 WITHSCORES
1) "v2" 2) "2.0" 3) "v3" 4) "3.0"
Empty list returned if key doesn't exist.
$ ZRANGE z_key_no_exist 0 2 WITHSCORES
(empty list or set)