Skip to content

Commit ec172e7

Browse files
Restoring ZRANGE desc for Redis < 6.2.0 (#1697)
1 parent cb58e96 commit ec172e7

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

redis/commands/core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,13 @@ def zrange(self, name, start, end, desc=False, withscores=False,
25202520
``offset`` and ``num`` are specified, then return a slice of the range.
25212521
Can't be provided when using ``bylex``.
25222522
"""
2523+
# Need to support ``desc`` also when using old redis version
2524+
# because it was supported in 3.5.3 (of redis-py)
2525+
if not byscore and not bylex and (offset is None and num is None) \
2526+
and desc:
2527+
return self.zrevrange(name, start, end, withscores,
2528+
score_cast_func)
2529+
25232530
return self._zrange('ZRANGE', None, name, start, end, desc, byscore,
25242531
bylex, withscores, score_cast_func, offset, num)
25252532

tests/test_commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ def test_zrange(self, r):
18671867
assert r.zrange('a', 0, 1) == [b'a1', b'a2']
18681868
assert r.zrange('a', 1, 2) == [b'a2', b'a3']
18691869
assert r.zrange('a', 0, 2) == [b'a1', b'a2', b'a3']
1870+
assert r.zrange('a', 0, 2, desc=True) == [b'a3', b'a2', b'a1']
18701871

18711872
# withscores
18721873
assert r.zrange('a', 0, 1, withscores=True) == \

0 commit comments

Comments
 (0)