diff options
| author | Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> | 2021-07-29 16:41:46 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-29 16:41:46 +0300 |
| commit | 53fe4d3eae75cabfb635eae5ae9197efa0bf86c3 (patch) | |
| tree | dfb7943c2215f97d1b7d3f2b165c54eb27e35093 | |
| parent | c7ecb1d4aa68820e000f88c23f6ff3afd4166b8a (diff) | |
| download | redis-py-53fe4d3eae75cabfb635eae5ae9197efa0bf86c3.tar.gz | |
Zrangestore (#1521)
| -rwxr-xr-x | redis/client.py | 9 | ||||
| -rw-r--r-- | tests/test_commands.py | 10 |
2 files changed, 19 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index ea36ef0..33b0374 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3056,6 +3056,15 @@ class Redis: } return self.execute_command(*pieces, **options) + def zrangestore(self, dest, name, start, end): + """ + Stores in ``dest`` the result of a range of values from sorted set + ``name`` between ``start`` and ``end`` sorted in ascending order. + + ``start`` and ``end`` can be negative, indicating the end of the range. + """ + return self.execute_command('ZRANGESTORE', dest, name, start, end) + def zrangebylex(self, name, min, max, start=None, num=None): """ Return the lexicographical range of values from sorted set ``name`` diff --git a/tests/test_commands.py b/tests/test_commands.py index 62394a4..8411e5e 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1605,6 +1605,16 @@ class TestRedisCommands: assert r.zrange('a', 0, 1, withscores=True, score_cast_func=int) == \ [(b'a1', 1), (b'a2', 2)] + @skip_if_server_version_lt('6.2.0') + def test_zrangestore(self, r): + r.zadd('a', {'a1': 1, 'a2': 2, 'a3': 3}) + assert r.zrangestore('b', 'a', 0, 1) + assert r.zrange('b', 0, -1) == [b'a1', b'a2'] + assert r.zrangestore('b', 'a', 1, 2) + assert r.zrange('b', 0, -1) == [b'a2', b'a3'] + assert r.zrange('b', 0, -1, withscores=True) == \ + [(b'a2', 2), (b'a3', 3)] + @skip_if_server_version_lt('2.8.9') def test_zrangebylex(self, r): r.zadd('a', {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0}) |
