From 8d78790b7a333991ffba0129da21b41cc2e8a765 Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Thu, 14 Oct 2021 11:56:59 +0200 Subject: [PATCH 1/5] implement ROLE --- redis/commands.py | 8 ++++++++ tests/test_commands.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/redis/commands.py b/redis/commands.py index eb7cea54f6..bf1ffa198e 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -297,6 +297,14 @@ def bgsave(self, schedule=True): pieces.append("SCHEDULE") return self.execute_command('BGSAVE', *pieces) + def role(self): + """ + Provide information on the role of a Redis instance in + the context of replication, by returning if the instance + is currently a master, slave, or sentinel. + """ + return self.execute_command('ROLE') + def client_kill(self, address): "Disconnects the client at ``address`` (ip:port)" return self.execute_command('CLIENT KILL', address) diff --git a/tests/test_commands.py b/tests/test_commands.py index 2be8923e0e..7bf39053b4 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -551,6 +551,9 @@ def test_ping(self, r): def test_quit(self, r): assert r.quit() + def test_role(self, r): + assert r.role()[0] == b'master' + def test_slowlog_get(self, r, slowlog): assert r.slowlog_reset() unicode_string = chr(3456) + 'abcd' + chr(3421) From ddd6bfa9303a1fa7eb593a6494c1db18b82abc52 Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Thu, 14 Oct 2021 16:25:45 +0200 Subject: [PATCH 2/5] @skip_if_server_version_lt('2.8.12') --- tests/test_commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index 7bf39053b4..469c0a4698 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -551,6 +551,7 @@ def test_ping(self, r): def test_quit(self, r): assert r.quit() + @skip_if_server_version_lt('2.8.12') def test_role(self, r): assert r.role()[0] == b'master' From 19580561c1b2494781a9e88bc8f2d1b6b7b729ab Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Mon, 18 Oct 2021 09:38:55 +0200 Subject: [PATCH 3/5] extend test --- tests/test_commands.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index 469c0a4698..8072e52783 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -554,6 +554,8 @@ def test_quit(self, r): @skip_if_server_version_lt('2.8.12') def test_role(self, r): assert r.role()[0] == b'master' + assert r.role()[1] == 0 + assert r.role()[2] == [] def test_slowlog_get(self, r, slowlog): assert r.slowlog_reset() From a552c4717f5bf383de2a443dcebc7ca7ee5bd802 Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Tue, 23 Nov 2021 11:04:44 +0100 Subject: [PATCH 4/5] Update test --- tests/test_commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index 5b9ba3f2f2..b732702eb8 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -579,8 +579,8 @@ def test_quit(self, r): @skip_if_server_version_lt('2.8.12') def test_role(self, r): assert r.role()[0] == b'master' - assert r.role()[1] == 0 - assert r.role()[2] == [] + assert isinstance(r.role()[1], int) + assert isinstance(r.role()[2], list) def test_slowlog_get(self, r, slowlog): assert r.slowlog_reset() From d1ae2eb7f183103a8eff781beb52eec7446ad2a3 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" Date: Thu, 2 Dec 2021 19:22:03 +0200 Subject: [PATCH 5/5] master merge, fixing tests with now cluster --- redis/commands/core.py | 10 +++++++--- tests/test_commands.py | 6 ++++-- tests/test_connection_pool.py | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index 48e53248c1..fec3095cc5 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -338,10 +338,10 @@ def role(self): Provide information on the role of a Redis instance in the context of replication, by returning if the instance is currently a master, slave, or sentinel. - + For more information check https://redis.io/commands/role """ - return self.execute_command('ROLE') + return self.execute_command("ROLE") def client_kill(self, address, **kwargs): """Disconnects the client at ``address`` (ip:port) @@ -874,11 +874,15 @@ def slowlog_get(self, num=None, **kwargs): For more information check https://redis.io/commands/slowlog-get """ + from redis.client import NEVER_DECODE + args = ["SLOWLOG GET"] if num is not None: args.append(num) decode_responses = self.get_connection_kwargs().get("decode_responses", False) - return self.execute_command(*args, decode_responses=decode_responses, **kwargs) + if decode_responses is True: + kwargs[NEVER_DECODE] = [] + return self.execute_command(*args, **kwargs) def slowlog_len(self, **kwargs): """ diff --git a/tests/test_commands.py b/tests/test_commands.py index af52fbd9f2..556df840ad 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -653,12 +653,14 @@ def test_ping(self, r): def test_quit(self, r): assert r.quit() - @skip_if_server_version_lt('2.8.12') + @skip_if_server_version_lt("2.8.12") + @pytest.mark.onlynoncluster def test_role(self, r): - assert r.role()[0] == b'master' + assert r.role()[0] == b"master" assert isinstance(r.role()[1], int) assert isinstance(r.role()[2], list) + @pytest.mark.onlynoncluster def test_slowlog_get(self, r, slowlog): assert r.slowlog_reset() unicode_string = chr(3456) + "abcd" + chr(3421) diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index 276e77cdb9..138fcad4c9 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -450,7 +450,7 @@ class MyConnection(redis.UnixDomainSocketConnection): pass pool = redis.ConnectionPool.from_url( - 'unix:///socket', connection_class=MyConnection + "unix:///socket", connection_class=MyConnection ) assert pool.connection_class == MyConnection @@ -469,7 +469,7 @@ class MyConnection(redis.SSLConnection): pass pool = redis.ConnectionPool.from_url( - 'rediss://my.host', connection_class=MyConnection + "rediss://my.host", connection_class=MyConnection ) assert pool.connection_class == MyConnection