From 7d43a97bc7de62d8eefcb4b552d75d1e10d7e7c1 Mon Sep 17 00:00:00 2001 From: Shaya Potter Date: Wed, 10 Jul 2024 19:45:06 +0300 Subject: [PATCH] add CLIENT KILL maxAge support (v4) (#2761) --- packages/client/lib/commands/CLIENT_KILL.spec.ts | 10 ++++++++++ packages/client/lib/commands/CLIENT_KILL.ts | 13 +++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/client/lib/commands/CLIENT_KILL.spec.ts b/packages/client/lib/commands/CLIENT_KILL.spec.ts index 2fe894f361..733aaca858 100644 --- a/packages/client/lib/commands/CLIENT_KILL.spec.ts +++ b/packages/client/lib/commands/CLIENT_KILL.spec.ts @@ -65,6 +65,16 @@ describe('CLIENT KILL', () => { ); }); + it('MAXAGE', () => { + assert.deepEqual( + transformArguments({ + filter: ClientKillFilters.MAXAGE, + maxAge: 10 + }), + ['CLIENT', 'KILL', 'MAXAGE', '10'] + ); + }); + describe('SKIP_ME', () => { it('undefined', () => { assert.deepEqual( diff --git a/packages/client/lib/commands/CLIENT_KILL.ts b/packages/client/lib/commands/CLIENT_KILL.ts index adb2a5a656..f0b31e5cac 100644 --- a/packages/client/lib/commands/CLIENT_KILL.ts +++ b/packages/client/lib/commands/CLIENT_KILL.ts @@ -6,7 +6,8 @@ export enum ClientKillFilters { ID = 'ID', TYPE = 'TYPE', USER = 'USER', - SKIP_ME = 'SKIPME' + SKIP_ME = 'SKIPME', + MAXAGE = 'MAXAGE' } interface KillFilter { @@ -37,7 +38,11 @@ type KillSkipMe = ClientKillFilters.SKIP_ME | (KillFilter { + maxAge: number; +} + +type KillFilters = KillAddress | KillLocalAddress | KillId | KillType | KillUser | KillSkipMe | KillMaxage; export function transformArguments(filters: KillFilters | Array): RedisCommandArguments { const args = ['CLIENT', 'KILL']; @@ -89,6 +94,10 @@ function pushFilter(args: RedisCommandArguments, filter: KillFilters): void { case ClientKillFilters.SKIP_ME: args.push(filter.skipMe ? 'yes' : 'no'); break; + + case ClientKillFilters.MAXAGE: + args.push(filter.maxAge.toString()); + break; } }