From 4202d87f8d59ddf72ea8468343ef8f274b40f9ae Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Sun, 25 Jul 2021 16:08:19 +0300 Subject: [PATCH 1/7] zrangestore --- redis/client.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/redis/client.py b/redis/client.py index 160f495c1f..11e72340de 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3048,6 +3048,19 @@ 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. + + ``withscores`` indicates to return the scores along with the values. + The return type is a list of (value, score) pairs + """ + pieces = ['ZRANGESTORE', dest, name, start, end] + return self.execute_command(*pieces) + def zrangebylex(self, name, min, max, start=None, num=None): """ Return the lexicographical range of values from sorted set ``name`` From 3f00f907fde132fab0cd994d08e66010b75b1306 Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Sun, 25 Jul 2021 16:08:19 +0300 Subject: [PATCH 2/7] zrangestore --- redis/client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/redis/client.py b/redis/client.py index 160f495c1f..20baa83a4a 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3048,6 +3048,19 @@ 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. + + ``withscores`` indicates to return the scores along with the values. + The return type is a list of (value, score) pairs + """ + pieces = ['ZRANGESTORE', dest, name, start, end] + return self.execute_command(*pieces) + def zrangebylex(self, name, min, max, start=None, num=None): """ Return the lexicographical range of values from sorted set ``name`` @@ -3066,7 +3079,7 @@ def zrangebylex(self, name, min, max, start=None, num=None): def zrevrangebylex(self, name, max, min, start=None, num=None): """ - Return the reversed lexicographical range of values from sorted set + Return the reversed lexicographical range of valuees from sorted set ``name`` between ``max`` and ``min``. If ``start`` and ``num`` are specified, then return a slice of the From 4347f5e6c1fb05049fc633228428648184156f8c Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Sun, 25 Jul 2021 16:18:48 +0300 Subject: [PATCH 3/7] test --- redis/client.py | 3 --- tests/test_commands.py | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/redis/client.py b/redis/client.py index b15ba61e9e..2e3954848b 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3054,9 +3054,6 @@ def zrangestore(self, dest, name, start, end): ``name`` between ``start`` and ``end`` sorted in ascending order. ``start`` and ``end`` can be negative, indicating the end of the range. - - ``withscores`` indicates to return the scores along with the values. - The return type is a list of (value, score) pairs """ return self.execute_command('ZRANGESTORE', dest, name, start, end) diff --git a/tests/test_commands.py b/tests/test_commands.py index 3f0a82f721..152e8883c1 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1588,6 +1588,13 @@ def test_zrange(self, r): assert r.zrange('a', 0, 1, withscores=True, score_cast_func=int) == \ [(b'a1', 1), (b'a2', 2)] + 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'] + @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}) From 8e6bd17b17bab6df1654b7fb348dc74a410a2fd6 Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Sun, 25 Jul 2021 16:18:48 +0300 Subject: [PATCH 4/7] test --- redis/client.py | 3 --- tests/test_commands.py | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/redis/client.py b/redis/client.py index b15ba61e9e..2e3954848b 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3054,9 +3054,6 @@ def zrangestore(self, dest, name, start, end): ``name`` between ``start`` and ``end`` sorted in ascending order. ``start`` and ``end`` can be negative, indicating the end of the range. - - ``withscores`` indicates to return the scores along with the values. - The return type is a list of (value, score) pairs """ return self.execute_command('ZRANGESTORE', dest, name, start, end) diff --git a/tests/test_commands.py b/tests/test_commands.py index 3f0a82f721..e6cfa88dd0 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1588,6 +1588,14 @@ def test_zrange(self, r): assert r.zrange('a', 0, 1, withscores=True, score_cast_func=int) == \ [(b'a1', 1), (b'a2', 2)] + 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}) From 93affba59a8579101e6d3c134e07609a0edb2982 Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Sun, 25 Jul 2021 16:22:00 +0300 Subject: [PATCH 5/7] flake8 --- tests/test_commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index e6cfa88dd0..a1cf0b4234 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1594,7 +1594,8 @@ def test_zrangestore(self, r): 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)] + 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): From 40eda11935f99173dddf506400d96429d68645fe Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Sun, 25 Jul 2021 16:26:28 +0300 Subject: [PATCH 6/7] skip if version lt --- tests/test_commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index a1cf0b4234..d32eb3832b 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1588,6 +1588,7 @@ 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) From b4611578f24558293a8577ab329fe0d6e52ea5a8 Mon Sep 17 00:00:00 2001 From: Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> Date: Tue, 27 Jul 2021 13:35:45 +0300 Subject: [PATCH 7/7] Update client.py --- redis/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/client.py b/redis/client.py index 2e3954848b..f61a35d686 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3075,7 +3075,7 @@ def zrangebylex(self, name, min, max, start=None, num=None): def zrevrangebylex(self, name, max, min, start=None, num=None): """ - Return the reversed lexicographical range of valuees from sorted set + Return the reversed lexicographical range of values from sorted set ``name`` between ``max`` and ``min``. If ``start`` and ``num`` are specified, then return a slice of the