Skip to content

Commit

Permalink
Support the MAXAGE option for CLIENT KILL (redis#3187)
Browse files Browse the repository at this point in the history
Issue redis#3154

The CLIENT KILL command has a new option, called MAXAGE, to kill
clients older than a given age. Add support for this new option.

Co-authored-by: Gabriel Erzse <gabriel.erzse@redis.com>
  • Loading branch information
gerzse and gerzse committed Jul 10, 2024
1 parent 29a5db8 commit 2239f4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,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 @@ -474,6 +475,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 @@ -496,6 +498,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

0 comments on commit 2239f4b

Please sign in to comment.