diff options
author | dvora-h <67596500+dvora-h@users.noreply.github.com> | 2022-05-08 15:05:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 15:05:43 +0300 |
commit | 3a8802214a05fed4a0828b1f2965ac140e11ee32 (patch) | |
tree | 9a8dd1c3024af6d2ddfc99774034d96ed93f8259 | |
parent | 061d97abe21d3a8ce9738330cabf771dd05c8dc1 (diff) | |
download | redis-py-3a8802214a05fed4a0828b1f2965ac140e11ee32.tar.gz |
Add support for COMMAND LIST (#2149)
* Add support for COMMAND LIST
* style change
-rw-r--r-- | redis/commands/core.py | 28 | ||||
-rw-r--r-- | tests/test_commands.py | 10 |
2 files changed, 38 insertions, 0 deletions
diff --git a/redis/commands/core.py b/redis/commands/core.py index 6526ef1..073161f 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -769,6 +769,34 @@ class ManagementCommands(CommandsProtocol): def command_count(self, **kwargs) -> ResponseT: return self.execute_command("COMMAND COUNT", **kwargs) + def command_list( + self, + module: Optional[str] = None, + category: Optional[str] = None, + pattern: Optional[str] = None, + ) -> ResponseT: + """ + Return an array of the server's command names. + You can use one of the following filters: + ``module``: get the commands that belong to the module + ``category``: get the commands in the ACL category + ``pattern``: get the commands that match the given pattern + + For more information see https://redis.io/commands/command-list/ + """ + pieces = [] + if module is not None: + pieces.extend(["MODULE", module]) + if category is not None: + pieces.extend(["ACLCAT", category]) + if pattern is not None: + pieces.extend(["PATTERN", pattern]) + + if pieces: + pieces.insert(0, "FILTERBY") + + return self.execute_command("COMMAND LIST", *pieces) + def command_getkeysandflags(self, *args: List[str]) -> List[Union[str, List[str]]]: """ Returns array of keys from a full Redis command and their usage flags. diff --git a/tests/test_commands.py b/tests/test_commands.py index b7287b4..00eac17 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -4550,6 +4550,16 @@ class TestRedisCommands: with pytest.raises(NotImplementedError): r.command_docs("set") + @skip_if_server_version_lt("7.0.0") + @skip_if_redis_enterprise() + def test_command_list(self, r: redis.Redis): + assert len(r.command_list()) > 300 + assert len(r.command_list(module="fakemod")) == 0 + assert len(r.command_list(category="list")) > 15 + assert "lpop" in r.command_list(pattern="l*") + with pytest.raises(redis.ResponseError): + r.command_list(category="list", pattern="l*") + @pytest.mark.onlynoncluster @skip_if_server_version_lt("2.8.13") @skip_if_redis_enterprise() |