diff --git a/redis/commands/core.py b/redis/commands/core.py index 462fba7f82..fec3095cc5 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -333,6 +333,16 @@ def bgsave(self, schedule=True, **kwargs): pieces.append("SCHEDULE") return self.execute_command("BGSAVE", *pieces, **kwargs) + 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") + def client_kill(self, address, **kwargs): """Disconnects the client at ``address`` (ip:port) @@ -864,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 7c7d0f3d9e..556df840ad 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -653,6 +653,13 @@ def test_ping(self, r): def test_quit(self, r): assert r.quit() + @skip_if_server_version_lt("2.8.12") + @pytest.mark.onlynoncluster + def test_role(self, r): + 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() 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