diff options
| author | Andy McCurdy <andy@andymccurdy.com> | 2019-09-30 12:50:04 -0700 |
|---|---|---|
| committer | Andy McCurdy <andy@andymccurdy.com> | 2019-12-28 22:23:43 -0800 |
| commit | a7ff4cfcebe4f819f1979f7ef44fdad8fb22c4ec (patch) | |
| tree | aec16d85281e3acbd918f1e6c686532b015d3922 | |
| parent | 7ff9a0bc3a2ca68601fe0b8bf5bed9840393bc01 (diff) | |
| download | redis-py-a7ff4cfcebe4f819f1979f7ef44fdad8fb22c4ec.tar.gz | |
Implement ACL CAT
| -rwxr-xr-x | redis/client.py | 18 | ||||
| -rw-r--r-- | tests/test_commands.py | 12 |
2 files changed, 27 insertions, 3 deletions
diff --git a/redis/client.py b/redis/client.py index 9591eeb..4bc8eb7 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 CAT': lambda r: list(map(nativestr, r)), 'ACL GENPASS': nativestr, 'ACL WHOAMI': nativestr, 'CLIENT GETNAME': lambda r: r and nativestr(r), @@ -872,14 +873,25 @@ class Redis(object): # SERVER INFORMATION # ACL methods - def acl_whoami(self): - "Get the username for the current connection" - return self.execute_command('ACL WHOAMI') + def acl_cat(self, category=None): + """ + Returns a list of categories or commands within a category. + + If ``category`` is not supplied, returns a list of all categories. + If ``category`` is supplied, returns a list of all commands within + that category. + """ + pieces = [category] if category else [] + return self.execute_command('ACL CAT', *pieces) def acl_genpass(self): "Generate a random password value" return self.execute_command('ACL GENPASS') + 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 14a2b56..d26a7de 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -67,6 +67,18 @@ class TestRedisCommands(object): # SERVER INFORMATION @skip_if_server_version_lt('6.0.0') + def test_acl_cat_no_category(self, r): + categories = r.acl_cat() + assert isinstance(categories, list) + assert 'read' in categories + + @skip_if_server_version_lt('6.0.0') + def test_acl_cat_with_category(self, r): + commands = r.acl_cat('read') + assert isinstance(commands, list) + assert 'get' in commands + + @skip_if_server_version_lt('6.0.0') def test_acl_genpass(self, r): password = r.acl_genpass() assert isinstance(password, basestring) |
