Skip to content

Commit 2820e87

Browse files
committed
Support the MAXAGE option for CLIENT KILL (#3187)
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. Co-authored-by: Gabriel Erzse <[email protected]>
1 parent 87a8c48 commit 2820e87

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

redis/commands/core.py

+4
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ def client_kill_filter(
461461
skipme: Union[bool, None] = None,
462462
laddr: Union[bool, None] = None,
463463
user: str = None,
464+
maxage: Union[int, None] = None,
464465
**kwargs,
465466
) -> ResponseT:
466467
"""
@@ -474,6 +475,7 @@ def client_kill_filter(
474475
options. If skipme is not provided, the server defaults to skipme=True
475476
:param laddr: Kills a client by its 'local (bind) address:port'
476477
:param user: Kills a client for a specific user name
478+
:param maxage: Kills clients that are older than the specified age in seconds
477479
"""
478480
args = []
479481
if _type is not None:
@@ -496,6 +498,8 @@ def client_kill_filter(
496498
args.extend((b"LADDR", laddr))
497499
if user is not None:
498500
args.extend((b"USER", user))
501+
if maxage is not None:
502+
args.extend((b"MAXAGE", maxage))
499503
if not args:
500504
raise DataError(
501505
"CLIENT KILL <filter> <value> ... ... <filter> "

tests/test_commands.py

+9
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,15 @@ def test_client_kill_filter_by_user(self, r, request):
707707
assert c["user"] != killuser
708708
r.acl_deluser(killuser)
709709

710+
@skip_if_server_version_lt("7.4.0")
711+
@skip_if_redis_enterprise()
712+
def test_client_kill_filter_by_maxage(self, r, request):
713+
_get_client(redis.Redis, request, flushdb=False)
714+
time.sleep(4)
715+
assert len(r.client_list()) == 2
716+
r.client_kill_filter(maxage=2)
717+
assert len(r.client_list()) == 1
718+
710719
@pytest.mark.onlynoncluster
711720
@skip_if_server_version_lt("2.9.50")
712721
@skip_if_redis_enterprise()

0 commit comments

Comments
 (0)