Skip to content

Commit

Permalink
add CLIENT KILL maxAge support (v4) (#2761)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpotter authored Jul 10, 2024
1 parent b4df2b2 commit 7d43a97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/client/lib/commands/CLIENT_KILL.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 11 additions & 2 deletions packages/client/lib/commands/CLIENT_KILL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export enum ClientKillFilters {
ID = 'ID',
TYPE = 'TYPE',
USER = 'USER',
SKIP_ME = 'SKIPME'
SKIP_ME = 'SKIPME',
MAXAGE = 'MAXAGE'
}

interface KillFilter<T extends ClientKillFilters> {
Expand Down Expand Up @@ -37,7 +38,11 @@ type KillSkipMe = ClientKillFilters.SKIP_ME | (KillFilter<ClientKillFilters.SKIP
skipMe: boolean;
});

type KillFilters = KillAddress | KillLocalAddress | KillId | KillType | KillUser | KillSkipMe;
interface KillMaxage extends KillFilter<ClientKillFilters.MAXAGE> {
maxAge: number;
}

type KillFilters = KillAddress | KillLocalAddress | KillId | KillType | KillUser | KillSkipMe | KillMaxage;

export function transformArguments(filters: KillFilters | Array<KillFilters>): RedisCommandArguments {
const args = ['CLIENT', 'KILL'];
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 7d43a97

Please sign in to comment.