diff options
author | Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> | 2021-11-11 11:31:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-11 12:31:19 +0200 |
commit | ec172e74bbccd32627835d67eddac704fe9ba31b (patch) | |
tree | ce02a106846d5b4aa4c20a32f6a473f6d8a02d38 | |
parent | cb58e968c2313e447b5b96fbbe8be1af306e1849 (diff) | |
download | redis-py-ec172e74bbccd32627835d67eddac704fe9ba31b.tar.gz |
Restoring ZRANGE desc for Redis < 6.2.0 (#1697)
-rw-r--r-- | redis/commands/core.py | 7 | ||||
-rw-r--r-- | tests/test_commands.py | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/redis/commands/core.py b/redis/commands/core.py index 90997ff..67f1bfa 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -2520,6 +2520,13 @@ class CoreCommands: ``offset`` and ``num`` are specified, then return a slice of the range. Can't be provided when using ``bylex``. """ + # Need to support ``desc`` also when using old redis version + # because it was supported in 3.5.3 (of redis-py) + if not byscore and not bylex and (offset is None and num is None) \ + and desc: + return self.zrevrange(name, start, end, withscores, + score_cast_func) + return self._zrange('ZRANGE', None, name, start, end, desc, byscore, bylex, withscores, score_cast_func, offset, num) diff --git a/tests/test_commands.py b/tests/test_commands.py index 4991f89..330ba28 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1867,6 +1867,7 @@ class TestRedisCommands: assert r.zrange('a', 0, 1) == [b'a1', b'a2'] assert r.zrange('a', 1, 2) == [b'a2', b'a3'] assert r.zrange('a', 0, 2) == [b'a1', b'a2', b'a3'] + assert r.zrange('a', 0, 2, desc=True) == [b'a3', b'a2', b'a1'] # withscores assert r.zrange('a', 0, 1, withscores=True) == \ |