diff --git a/redis/commands/core.py b/redis/commands/core.py index 8bbcda3a69..8c97cc7c3e 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -745,6 +745,34 @@ def command_info(self, **kwargs) -> None: 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 59754123ac..cf752bb989 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -4520,6 +4520,16 @@ def test_command_docs(self, r): 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()