Skip to content

Commit 67f8746

Browse files
gerzsevladvildanov
authored andcommitted
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 8fa4d82 commit 67f8746

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
@@ -459,6 +459,7 @@ def client_kill_filter(
459459
skipme: Union[bool, None] = None,
460460
laddr: Union[bool, None] = None,
461461
user: str = None,
462+
maxage: Union[int, None] = None,
462463
**kwargs,
463464
) -> ResponseT:
464465
"""
@@ -472,6 +473,7 @@ def client_kill_filter(
472473
options. If skipme is not provided, the server defaults to skipme=True
473474
:param laddr: Kills a client by its 'local (bind) address:port'
474475
:param user: Kills a client for a specific user name
476+
:param maxage: Kills clients that are older than the specified age in seconds
475477
"""
476478
args = []
477479
if _type is not None:
@@ -494,6 +496,8 @@ def client_kill_filter(
494496
args.extend((b"LADDR", laddr))
495497
if user is not None:
496498
args.extend((b"USER", user))
499+
if maxage is not None:
500+
args.extend((b"MAXAGE", maxage))
497501
if not args:
498502
raise DataError(
499503
"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)