Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zrangestore #1521

Merged
merged 11 commits into from
Jul 29, 2021
9 changes: 9 additions & 0 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,15 @@ def zrange(self, name, start, end, desc=False, withscores=False,
}
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``
Expand Down
10 changes: 10 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,16 @@ def test_zrange(self, r):
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})
Expand Down