Skip to content
Merged
16 changes: 15 additions & 1 deletion redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down