Skip to content

Commit 3a88022

Browse files
authored
Add support for COMMAND LIST (#2149)
* Add support for COMMAND LIST * style change
1 parent 061d97a commit 3a88022

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

redis/commands/core.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,34 @@ def command_info(self, **kwargs) -> None:
769769
def command_count(self, **kwargs) -> ResponseT:
770770
return self.execute_command("COMMAND COUNT", **kwargs)
771771

772+
def command_list(
773+
self,
774+
module: Optional[str] = None,
775+
category: Optional[str] = None,
776+
pattern: Optional[str] = None,
777+
) -> ResponseT:
778+
"""
779+
Return an array of the server's command names.
780+
You can use one of the following filters:
781+
``module``: get the commands that belong to the module
782+
``category``: get the commands in the ACL category
783+
``pattern``: get the commands that match the given pattern
784+
785+
For more information see https://redis.io/commands/command-list/
786+
"""
787+
pieces = []
788+
if module is not None:
789+
pieces.extend(["MODULE", module])
790+
if category is not None:
791+
pieces.extend(["ACLCAT", category])
792+
if pattern is not None:
793+
pieces.extend(["PATTERN", pattern])
794+
795+
if pieces:
796+
pieces.insert(0, "FILTERBY")
797+
798+
return self.execute_command("COMMAND LIST", *pieces)
799+
772800
def command_getkeysandflags(self, *args: List[str]) -> List[Union[str, List[str]]]:
773801
"""
774802
Returns array of keys from a full Redis command and their usage flags.

tests/test_commands.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4550,6 +4550,16 @@ def test_command_docs(self, r):
45504550
with pytest.raises(NotImplementedError):
45514551
r.command_docs("set")
45524552

4553+
@skip_if_server_version_lt("7.0.0")
4554+
@skip_if_redis_enterprise()
4555+
def test_command_list(self, r: redis.Redis):
4556+
assert len(r.command_list()) > 300
4557+
assert len(r.command_list(module="fakemod")) == 0
4558+
assert len(r.command_list(category="list")) > 15
4559+
assert "lpop" in r.command_list(pattern="l*")
4560+
with pytest.raises(redis.ResponseError):
4561+
r.command_list(category="list", pattern="l*")
4562+
45534563
@pytest.mark.onlynoncluster
45544564
@skip_if_server_version_lt("2.8.13")
45554565
@skip_if_redis_enterprise()

0 commit comments

Comments
 (0)