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

Support the MAXAGE option for CLIENT KILL #3187

Merged
merged 2 commits into from
May 9, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def client_kill_filter(
skipme: Union[bool, None] = None,
laddr: Union[bool, None] = None,
user: str = None,
maxage: Union[int, None] = None,
**kwargs,
) -> ResponseT:
"""
Expand All @@ -472,6 +473,7 @@ def client_kill_filter(
options. If skipme is not provided, the server defaults to skipme=True
:param laddr: Kills a client by its 'local (bind) address:port'
:param user: Kills a client for a specific user name
:param maxage: Kills clients that are older than the specified age in seconds
"""
args = []
if _type is not None:
Expand All @@ -494,6 +496,8 @@ def client_kill_filter(
args.extend((b"LADDR", laddr))
if user is not None:
args.extend((b"USER", user))
if maxage is not None:
args.extend((b"MAXAGE", maxage))
if not args:
raise DataError(
"CLIENT KILL <filter> <value> ... ... <filter> "
Expand Down
9 changes: 9 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,15 @@ def test_client_kill_filter_by_user(self, r, request):
assert c["user"] != killuser
r.acl_deluser(killuser)

@skip_if_server_version_lt("7.4.0")
@skip_if_redis_enterprise()
def test_client_kill_filter_by_maxage(self, r, request):
_get_client(redis.Redis, request, flushdb=False)
time.sleep(4)
assert len(r.client_list()) == 2
r.client_kill_filter(maxage=2)
assert len(r.client_list()) == 1

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("2.9.50")
@skip_if_redis_enterprise()
Expand Down