forked from redis/node-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…ClientOptions`
- Loading branch information
Showing
14 changed files
with
323 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { strict as assert } from 'assert'; | ||
import { transformArguments } from './CLIENT_CACHING'; | ||
|
||
describe('CLIENT CACHING', () => { | ||
describe('transformArguments', () => { | ||
it('true', () => { | ||
assert.deepEqual( | ||
transformArguments(true), | ||
['CLIENT', 'CACHING', 'YES'] | ||
); | ||
}); | ||
|
||
it('false', () => { | ||
assert.deepEqual( | ||
transformArguments(false), | ||
['CLIENT', 'CACHING', 'NO'] | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { RedisCommandArguments } from '.'; | ||
|
||
export function transformArguments(value: boolean): RedisCommandArguments { | ||
return [ | ||
'CLIENT', | ||
'CACHING', | ||
value ? 'YES' : 'NO' | ||
]; | ||
} | ||
|
||
export declare function transformReply(): 'OK'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { strict as assert } from 'assert'; | ||
import { transformArguments } from './CLIENT_GETNAME'; | ||
|
||
describe('CLIENT GETNAME', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments(), | ||
['CLIENT', 'GETNAME'] | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { RedisCommandArguments } from '.'; | ||
|
||
export function transformArguments(): RedisCommandArguments { | ||
return ['CLIENT', 'GETNAME']; | ||
} | ||
|
||
export declare function transformReply(): string | null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { strict as assert } from 'assert'; | ||
import { transformArguments } from './CLIENT_GETREDIR'; | ||
|
||
describe('CLIENT GETREDIR', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments(), | ||
['CLIENT', 'GETREDIR'] | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { RedisCommandArguments } from '.'; | ||
|
||
export function transformArguments(): RedisCommandArguments { | ||
return ['CLIENT', 'GETREDIR']; | ||
} | ||
|
||
export declare function transformReply(): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { strict as assert } from 'assert'; | ||
import { ClientKillFilters, transformArguments } from './CLIENT_KILL'; | ||
|
||
describe('CLIENT KILL', () => { | ||
describe('transformArguments', () => { | ||
it('ADDRESS', () => { | ||
assert.deepEqual( | ||
transformArguments({ | ||
filter: ClientKillFilters.ADDRESS, | ||
address: 'ip:6379' | ||
}), | ||
['CLIENT', 'KILL', 'ADDR', 'ip:6379'] | ||
); | ||
}); | ||
|
||
it('LOCAL_ADDRESS', () => { | ||
assert.deepEqual( | ||
transformArguments({ | ||
filter: ClientKillFilters.LOCAL_ADDRESS, | ||
localAddress: 'ip:6379' | ||
}), | ||
['CLIENT', 'KILL', 'LADDR', 'ip:6379'] | ||
); | ||
}); | ||
|
||
describe('ID', () => { | ||
it('string', () => { | ||
assert.deepEqual( | ||
transformArguments({ | ||
filter: ClientKillFilters.ID, | ||
id: '1' | ||
}), | ||
['CLIENT', 'KILL', 'ID', '1'] | ||
); | ||
}); | ||
|
||
it('number', () => { | ||
assert.deepEqual( | ||
transformArguments({ | ||
filter: ClientKillFilters.ID, | ||
id: 1 | ||
}), | ||
['CLIENT', 'KILL', 'ID', '1'] | ||
); | ||
}); | ||
}); | ||
|
||
it('TYPE', () => { | ||
assert.deepEqual( | ||
transformArguments({ | ||
filter: ClientKillFilters.TYPE, | ||
type: 'master' | ||
}), | ||
['CLIENT', 'KILL', 'TYPE', 'master'] | ||
); | ||
}); | ||
|
||
it('USER', () => { | ||
assert.deepEqual( | ||
transformArguments({ | ||
filter: ClientKillFilters.USER, | ||
username: 'username' | ||
}), | ||
['CLIENT', 'KILL', 'USER', 'username'] | ||
); | ||
}); | ||
|
||
describe('SKIP_ME', () => { | ||
it('undefined', () => { | ||
assert.deepEqual( | ||
transformArguments(ClientKillFilters.SKIP_ME), | ||
['CLIENT', 'KILL', 'SKIPME'] | ||
); | ||
}); | ||
|
||
it('true', () => { | ||
assert.deepEqual( | ||
transformArguments({ | ||
filter: ClientKillFilters.SKIP_ME, | ||
skipMe: true | ||
}), | ||
['CLIENT', 'KILL', 'SKIPME', 'yes'] | ||
); | ||
}); | ||
|
||
it('false', () => { | ||
assert.deepEqual( | ||
transformArguments({ | ||
filter: ClientKillFilters.SKIP_ME, | ||
skipMe: false | ||
}), | ||
['CLIENT', 'KILL', 'SKIPME', 'no'] | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { RedisCommandArguments } from '.'; | ||
|
||
export enum ClientKillFilters { | ||
ADDRESS = 'ADDR', | ||
LOCAL_ADDRESS = 'LADDR', | ||
ID = 'ID', | ||
TYPE = 'TYPE', | ||
USER = 'USER', | ||
SKIP_ME = 'SKIPME' | ||
} | ||
|
||
interface KillFilter<T extends ClientKillFilters> { | ||
filter: T; | ||
} | ||
|
||
interface KillAddress extends KillFilter<ClientKillFilters.ADDRESS> { | ||
address: `${string}:${number}`; | ||
} | ||
|
||
interface KillLocalAddress extends KillFilter<ClientKillFilters.LOCAL_ADDRESS> { | ||
localAddress: `${string}:${number}`; | ||
} | ||
|
||
interface KillId extends KillFilter<ClientKillFilters.ID> { | ||
id: number | `${number}`; | ||
} | ||
|
||
interface KillType extends KillFilter<ClientKillFilters.TYPE> { | ||
type: 'normal' | 'master' | 'replica' | 'pubsub'; | ||
} | ||
|
||
interface KillUser extends KillFilter<ClientKillFilters.USER> { | ||
username: string; | ||
} | ||
|
||
type KillSkipMe = ClientKillFilters.SKIP_ME | (KillFilter<ClientKillFilters.SKIP_ME> & { | ||
skipMe: boolean; | ||
}); | ||
|
||
type KillFilters = KillAddress | KillLocalAddress | KillId | KillType | KillUser | KillSkipMe; | ||
|
||
export function transformArguments(filters: KillFilters | Array<KillFilters>): RedisCommandArguments { | ||
const args = ['CLIENT', 'KILL']; | ||
|
||
if (Array.isArray(filters)) { | ||
for (const filter of filters) { | ||
pushFilter(args, filter); | ||
} | ||
} else { | ||
pushFilter(args, filters); | ||
} | ||
|
||
return args; | ||
} | ||
|
||
function pushFilter(args: RedisCommandArguments, filter: KillFilters): void { | ||
if (filter === ClientKillFilters.SKIP_ME) { | ||
args.push('SKIPME'); | ||
return; | ||
} | ||
|
||
args.push(filter.filter); | ||
|
||
switch(filter.filter) { | ||
case ClientKillFilters.ADDRESS: | ||
args.push(filter.address); | ||
break; | ||
|
||
case ClientKillFilters.LOCAL_ADDRESS: | ||
args.push(filter.localAddress); | ||
break; | ||
|
||
case ClientKillFilters.ID: | ||
args.push( | ||
typeof filter.id === 'number' ? | ||
filter.id.toString() : | ||
filter.id | ||
); | ||
break; | ||
|
||
case ClientKillFilters.TYPE: | ||
args.push(filter.type); | ||
break; | ||
|
||
case ClientKillFilters.USER: | ||
args.push(filter.username); | ||
break; | ||
|
||
case ClientKillFilters.SKIP_ME: | ||
args.push(filter.skipMe ? 'yes' : 'no'); | ||
break; | ||
} | ||
} | ||
|
||
export declare function transformReply(): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { strict as assert } from 'assert'; | ||
import { transformArguments } from './CLIENT_SETNAME'; | ||
|
||
describe('CLIENT SETNAME', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments('name'), | ||
['CLIENT', 'SETNAME', 'name'] | ||
); | ||
}); | ||
}); |
Oops, something went wrong.