Skip to content

Commit c2d4621

Browse files
Adding ROLE Command (#1610)
Co-authored-by: Chayim <[email protected]>
1 parent 48b19df commit c2d4621

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

redis/commands/core.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,16 @@ def bgsave(self, schedule=True, **kwargs):
333333
pieces.append("SCHEDULE")
334334
return self.execute_command("BGSAVE", *pieces, **kwargs)
335335

336+
def role(self):
337+
"""
338+
Provide information on the role of a Redis instance in
339+
the context of replication, by returning if the instance
340+
is currently a master, slave, or sentinel.
341+
342+
For more information check https://redis.io/commands/role
343+
"""
344+
return self.execute_command("ROLE")
345+
336346
def client_kill(self, address, **kwargs):
337347
"""Disconnects the client at ``address`` (ip:port)
338348
@@ -864,11 +874,15 @@ def slowlog_get(self, num=None, **kwargs):
864874
865875
For more information check https://redis.io/commands/slowlog-get
866876
"""
877+
from redis.client import NEVER_DECODE
878+
867879
args = ["SLOWLOG GET"]
868880
if num is not None:
869881
args.append(num)
870882
decode_responses = self.get_connection_kwargs().get("decode_responses", False)
871-
return self.execute_command(*args, decode_responses=decode_responses, **kwargs)
883+
if decode_responses is True:
884+
kwargs[NEVER_DECODE] = []
885+
return self.execute_command(*args, **kwargs)
872886

873887
def slowlog_len(self, **kwargs):
874888
"""

tests/test_commands.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,13 @@ def test_ping(self, r):
653653
def test_quit(self, r):
654654
assert r.quit()
655655

656+
@skip_if_server_version_lt("2.8.12")
657+
@pytest.mark.onlynoncluster
658+
def test_role(self, r):
659+
assert r.role()[0] == b"master"
660+
assert isinstance(r.role()[1], int)
661+
assert isinstance(r.role()[2], list)
662+
656663
@pytest.mark.onlynoncluster
657664
def test_slowlog_get(self, r, slowlog):
658665
assert r.slowlog_reset()

0 commit comments

Comments
 (0)