summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvital Fine <79420960+AvitalFineRedis@users.noreply.github.com>2021-12-02 18:53:00 +0100
committerGitHub <noreply@github.com>2021-12-02 19:53:00 +0200
commitc2d4621d5da2f4506fb484eb787f004a235c76b1 (patch)
treebcc2e7f329996bc2ee97e1e5c18ed47dad028e54
parent48b19dfc526102864c7289cf1f3c4889c858d359 (diff)
downloadredis-py-c2d4621d5da2f4506fb484eb787f004a235c76b1.tar.gz
Adding ROLE Command (#1610)
Co-authored-by: Chayim <chayim@users.noreply.github.com>
-rw-r--r--redis/commands/core.py16
-rw-r--r--tests/test_commands.py7
2 files changed, 22 insertions, 1 deletions
diff --git a/redis/commands/core.py b/redis/commands/core.py
index 462fba7..fec3095 100644
--- a/redis/commands/core.py
+++ b/redis/commands/core.py
@@ -333,6 +333,16 @@ class ManagementCommands:
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 @@ class ManagementCommands:
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 7c7d0f3..556df84 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -653,6 +653,13 @@ class TestRedisCommands:
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()