From 5bb06d9b798b8d3a7f81233eaa64d78223f42222 Mon Sep 17 00:00:00 2001 From: Andy McCurdy Date: Mon, 30 Sep 2019 12:35:40 -0700 Subject: Implement ACL WHOAMI --- redis/client.py | 7 +++++++ tests/test_commands.py | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/redis/client.py b/redis/client.py index 982e6db..69d9d05 100755 --- a/redis/client.py +++ b/redis/client.py @@ -526,6 +526,7 @@ class Redis(object): string_keys_to_dict('XREAD XREADGROUP', parse_xread), string_keys_to_dict('BGREWRITEAOF BGSAVE', lambda r: True), { + 'ACL WHOAMI': nativestr, 'CLIENT GETNAME': lambda r: r and nativestr(r), 'CLIENT ID': int, 'CLIENT KILL': parse_client_kill, @@ -868,6 +869,12 @@ class Redis(object): return response # SERVER INFORMATION + + # ACL methods + def acl_whoami(self): + "Get the username for the current connection" + return self.execute_command('ACL WHOAMI') + def bgrewriteaof(self): "Tell the Redis server to rewrite the AOF file from data in memory." return self.execute_command('BGREWRITEAOF') diff --git a/tests/test_commands.py b/tests/test_commands.py index ef316af..9ad1fd0 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -7,7 +7,7 @@ import redis import time from redis._compat import (unichr, ascii_letters, iteritems, iterkeys, - itervalues, long) + itervalues, long, basestring) from redis.client import parse_info from redis import exceptions @@ -66,6 +66,11 @@ class TestRedisCommands(object): r['a'] # SERVER INFORMATION + @skip_if_server_version_lt('6.0.0') + def test_acl_whoami(self, r): + username = r.acl_whoami() + assert isinstance(username, basestring) + def test_client_list(self, r): clients = r.client_list() assert isinstance(clients[0], dict) -- cgit v1.2.1