Get all members in Sorted Set

Viewed 45929

I have a Sorted set and want to get all members of set. How to identify a max/min score for command :

zrange key min max 

?

3 Answers

In newer versions of redis (>= v6.2.0), if you want to get all members of a sorted set between two scores, you should use:

ZRANGE key min max BYSCORE

Adding the BYSCORE option makes redis treat the min & max arguments as scores rather than indices.

(As of this writing, ZRANGEBYSCORE still works, but is considered deprecated.)

Starting with Redis 6.2.0,

To get all the keys and its value together in a single query using the below,

zrange <KEY> 0 -1 WITHSCORES

The optional WITHSCORES argument supplements the command's reply with the scores of elements returned. The returned list contains value1,score1,...,valueN,scoreN instead of value1,...,valueN. Client libraries can return a more appropriate data type (suggestion: an array with (value, score) arrays/tuples).

Related