Skip to content

Commit 53fe4d3

Browse files
Zrangestore (#1521)
1 parent c7ecb1d commit 53fe4d3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

redis/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,6 +3056,15 @@ def zrange(self, name, start, end, desc=False, withscores=False,
30563056
}
30573057
return self.execute_command(*pieces, **options)
30583058

3059+
def zrangestore(self, dest, name, start, end):
3060+
"""
3061+
Stores in ``dest`` the result of a range of values from sorted set
3062+
``name`` between ``start`` and ``end`` sorted in ascending order.
3063+
3064+
``start`` and ``end`` can be negative, indicating the end of the range.
3065+
"""
3066+
return self.execute_command('ZRANGESTORE', dest, name, start, end)
3067+
30593068
def zrangebylex(self, name, min, max, start=None, num=None):
30603069
"""
30613070
Return the lexicographical range of values from sorted set ``name``

tests/test_commands.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,16 @@ def test_zrange(self, r):
16051605
assert r.zrange('a', 0, 1, withscores=True, score_cast_func=int) == \
16061606
[(b'a1', 1), (b'a2', 2)]
16071607

1608+
@skip_if_server_version_lt('6.2.0')
1609+
def test_zrangestore(self, r):
1610+
r.zadd('a', {'a1': 1, 'a2': 2, 'a3': 3})
1611+
assert r.zrangestore('b', 'a', 0, 1)
1612+
assert r.zrange('b', 0, -1) == [b'a1', b'a2']
1613+
assert r.zrangestore('b', 'a', 1, 2)
1614+
assert r.zrange('b', 0, -1) == [b'a2', b'a3']
1615+
assert r.zrange('b', 0, -1, withscores=True) == \
1616+
[(b'a2', 2), (b'a3', 3)]
1617+
16081618
@skip_if_server_version_lt('2.8.9')
16091619
def test_zrangebylex(self, r):
16101620
r.zadd('a', {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0})

0 commit comments

Comments
 (0)