Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for COMMAND LIST #2149

Merged
merged 4 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down