summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2019-09-30 12:35:40 -0700
committerAndy McCurdy <andy@andymccurdy.com>2019-12-28 22:23:43 -0800
commit5bb06d9b798b8d3a7f81233eaa64d78223f42222 (patch)
tree45acb908d26a1c92bf462d0e27949042f48ca5c1
parent75199289102fb41aef1a05d152f96d11fc1bd640 (diff)
downloadredis-py-5bb06d9b798b8d3a7f81233eaa64d78223f42222.tar.gz
Implement ACL WHOAMI
-rwxr-xr-xredis/client.py7
-rw-r--r--tests/test_commands.py7
2 files changed, 13 insertions, 1 deletions
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)