Skip to content

Commit

Permalink
Support the MAXAGE option for CLIENT KILL
Browse files Browse the repository at this point in the history
Issue #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.
  • Loading branch information
Gabriel Erzse committed Mar 18, 2024
1 parent 037d108 commit e1e95b5
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
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
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 e1e95b5

Please sign in to comment.