Sorted Set
ZRANGE
Returns the specified range of elements in the sorted set stored at key.
Arguments
keybodystrrequired
The key to get.
minbodyfloat | strrequired
The minimum value to include.
maxbodyfloat | strrequired
The maximum value to include.
"-inf" and "+inf" are also valid values for the ranges
withscoresbodybool
Whether to include the scores in the response.
revbodybool
Whether to reverse the order of the response.
sortbybody"BYSCORE" | "BYLEX"
If bylex
offsetbodyint
The offset to start from.
countbodyint
The number of elements to return.
Response
List[str] | List[Tuple[str, float]]
The values in the specified range.
If withscores is true, the members will be tuples of the form (member, score).
Example
redis.zadd("myset", {"a": 1, "b": 2, "c": 3})assert redis.zrange("myset", 0, 1) == ["a", "b"]Reverse
redis.zadd("myset", {"a": 1, "b": 2, "c": 3})assert redis.zrange("myset", 0, 1, rev=True) == ["c", "b"]Sorted
redis.zadd("myset", {"a": 1, "b": 2, "c": 3})assert redis.zrange("myset", 0, 1, sortby="BYSCORE") == ["a", "b"]With scores
redis.zadd("myset", {"a": 1, "b": 2, "c": 3})assert redis.zrange("myset", 0, 1, withscores=True) == [("a", 1), ("b", 2)]