You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
add all COMMAND commands
This commit is contained in:
28
lib/commands/COMMAND.spec.ts
Normal file
28
lib/commands/COMMAND.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { itWithClient, TestRedisServers } from '../test-utils';
|
||||
import { transformArguments } from './COMMAND';
|
||||
import { CommandCategories, CommandFlags } from './generic-transformers';
|
||||
|
||||
describe('COMMAND', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['COMMAND']
|
||||
);
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'client.command', async client => {
|
||||
assert.deepEqual(
|
||||
(await client.command()).find(command => command.name === 'ping'),
|
||||
{
|
||||
name: 'ping',
|
||||
arity: -1,
|
||||
flags: new Set([CommandFlags.STALE, CommandFlags.FAST]),
|
||||
firstKeyIndex: 0,
|
||||
lastKeyIndex: 0,
|
||||
step: 0,
|
||||
categories: new Set([CommandCategories.FAST, CommandCategories.CONNECTION])
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
12
lib/commands/COMMAND.ts
Normal file
12
lib/commands/COMMAND.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TransformArgumentsReply } from '.';
|
||||
import { CommandRawReply, CommandReply, transformCommandReply } from './generic-transformers';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(): TransformArgumentsReply {
|
||||
return ['COMMAND'];
|
||||
}
|
||||
|
||||
export function transformReply(reply: Array<CommandRawReply>): Array<CommandReply> {
|
||||
return reply.map(transformCommandReply);
|
||||
}
|
26
lib/commands/COMMAND_COUNT.spec.ts
Normal file
26
lib/commands/COMMAND_COUNT.spec.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { itWithClient, itWithCluster, TestRedisClusters, TestRedisServers } from '../test-utils';
|
||||
import { transformArguments } from './COMMAND_COUNT';
|
||||
|
||||
describe('COMMAND COUNT', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['COMMAND', 'COUNT']
|
||||
);
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'client.commandCount', async client => {
|
||||
assert.equal(
|
||||
typeof await client.commandCount(),
|
||||
'number'
|
||||
);
|
||||
});
|
||||
|
||||
itWithCluster(TestRedisClusters.OPEN, 'cluster.commandCount', async cluster => {
|
||||
assert.equal(
|
||||
typeof await cluster.commandCount(),
|
||||
'number'
|
||||
);
|
||||
});
|
||||
});
|
9
lib/commands/COMMAND_COUNT.ts
Normal file
9
lib/commands/COMMAND_COUNT.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { TransformArgumentsReply } from '.';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(): TransformArgumentsReply {
|
||||
return ['COMMAND', 'COUNT'];
|
||||
}
|
||||
|
||||
declare function transformReply(): number;
|
26
lib/commands/COMMAND_GETKEYS.spec.ts
Normal file
26
lib/commands/COMMAND_GETKEYS.spec.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { itWithClient, itWithCluster, TestRedisClusters, TestRedisServers } from '../test-utils';
|
||||
import { transformArguments } from './COMMAND_GETKEYS';
|
||||
|
||||
describe('COMMAND GETKEYS', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(['GET', 'key']),
|
||||
['COMMAND', 'GETKEYS', 'GET', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'client.commandGetKeys', async client => {
|
||||
assert.deepEqual(
|
||||
await client.commandGetKeys(['GET', 'key']),
|
||||
['key']
|
||||
);
|
||||
});
|
||||
|
||||
itWithCluster(TestRedisClusters.OPEN, 'cluster.commandGetKeys', async cluster => {
|
||||
assert.deepEqual(
|
||||
await cluster.commandGetKeys(['GET', 'key']),
|
||||
['key']
|
||||
);
|
||||
});
|
||||
});
|
9
lib/commands/COMMAND_GETKEYS.ts
Normal file
9
lib/commands/COMMAND_GETKEYS.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { TransformArgumentsReply } from '.';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(args: Array<string>): TransformArgumentsReply {
|
||||
return ['COMMAND', 'GETKEYS', ...args];
|
||||
}
|
||||
|
||||
declare function transformReply(): Array<string>;
|
28
lib/commands/COMMAND_INFO.spec.ts
Normal file
28
lib/commands/COMMAND_INFO.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { itWithClient, TestRedisServers } from '../test-utils';
|
||||
import { transformArguments } from './COMMAND_INFO';
|
||||
import { CommandCategories, CommandFlags } from './generic-transformers';
|
||||
|
||||
describe('COMMAND INFO', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(['PING']),
|
||||
['COMMAND', 'INFO', 'PING']
|
||||
);
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'client.commandInfo', async client => {
|
||||
assert.deepEqual(
|
||||
await client.commandInfo(['PING']),
|
||||
[{
|
||||
name: 'ping',
|
||||
arity: -1,
|
||||
flags: new Set([CommandFlags.STALE, CommandFlags.FAST]),
|
||||
firstKeyIndex: 0,
|
||||
lastKeyIndex: 0,
|
||||
step: 0,
|
||||
categories: new Set([CommandCategories.FAST, CommandCategories.CONNECTION])
|
||||
}]
|
||||
);
|
||||
});
|
||||
});
|
12
lib/commands/COMMAND_INFO.ts
Normal file
12
lib/commands/COMMAND_INFO.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TransformArgumentsReply } from '.';
|
||||
import { CommandRawReply, CommandReply, transformCommandReply } from './generic-transformers';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(commands: Array<string>): TransformArgumentsReply {
|
||||
return ['COMMAND', 'INFO', ...commands];
|
||||
}
|
||||
|
||||
export function transformReply(reply: Array<CommandRawReply | null>): Array<CommandReply | null> {
|
||||
return reply.map(command => command ? transformCommandReply(command) : null);
|
||||
}
|
@@ -21,7 +21,10 @@ import {
|
||||
pushStringTuplesArguments,
|
||||
pushVerdictArguments,
|
||||
pushVerdictArgument,
|
||||
pushOptionalVerdictArgument
|
||||
pushOptionalVerdictArgument,
|
||||
transformCommandReply,
|
||||
CommandFlags,
|
||||
CommandCategories
|
||||
} from './generic-transformers';
|
||||
|
||||
describe('Generic Transformers', () => {
|
||||
@@ -626,4 +629,27 @@ describe('Generic Transformers', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('transformCommandReply', () => {
|
||||
assert.deepEqual(
|
||||
transformCommandReply([
|
||||
'ping',
|
||||
-1,
|
||||
[CommandFlags.STALE, CommandFlags.FAST],
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
[CommandCategories.FAST, CommandCategories.CONNECTION]
|
||||
]),
|
||||
{
|
||||
name: 'ping',
|
||||
arity: -1,
|
||||
flags: new Set([CommandFlags.STALE, CommandFlags.FAST]),
|
||||
firstKeyIndex: 0,
|
||||
lastKeyIndex: 0,
|
||||
step: 0,
|
||||
categories: new Set([CommandCategories.FAST, CommandCategories.CONNECTION])
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -335,3 +335,79 @@ export function pushOptionalVerdictArgument(args: TransformArgumentsReply, name:
|
||||
|
||||
return pushVerdictArgument(args, value);
|
||||
}
|
||||
|
||||
export enum CommandFlags {
|
||||
WRITE = 'write', // command may result in modifications
|
||||
READONLY = 'readonly', // command will never modify keys
|
||||
DENYOOM = 'denyoom', // reject command if currently out of memory
|
||||
ADMIN = 'admin', // server admin command
|
||||
PUBSUB = 'pubsub', // pubsub-related command
|
||||
NOSCRIPT = 'noscript', // deny this command from scripts
|
||||
RANDOM = 'random', // command has random results, dangerous for scripts
|
||||
SORT_FOR_SCRIPT = 'sort_for_script', // if called from script, sort output
|
||||
LOADING = 'loading', // allow command while database is loading
|
||||
STALE = 'stale', // allow command while replica has stale data
|
||||
SKIP_MONITOR = 'skip_monitor', // do not show this command in MONITOR
|
||||
ASKING = 'asking', // cluster related - accept even if importing
|
||||
FAST = 'fast', // command operates in constant or log(N) time. Used for latency monitoring.
|
||||
MOVABLEKEYS = 'movablekeys' // keys have no pre-determined position. You must discover keys yourself.
|
||||
}
|
||||
|
||||
export enum CommandCategories {
|
||||
KEYSPACE = '@keyspace',
|
||||
READ = '@read',
|
||||
WRITE = '@write',
|
||||
SET = '@set',
|
||||
SORTEDSET = '@sortedset',
|
||||
LIST = '@list',
|
||||
HASH = '@hash',
|
||||
STRING = '@string',
|
||||
BITMAP = '@bitmap',
|
||||
HYPERLOGLOG = '@hyperloglog',
|
||||
GEO = '@geo',
|
||||
STREAM = '@stream',
|
||||
PUBSUB = '@pubsub',
|
||||
ADMIN = '@admin',
|
||||
FAST = '@fast',
|
||||
SLOW = '@slow',
|
||||
BLOCKING = '@blocking',
|
||||
DANGEROUS = '@dangerous',
|
||||
CONNECTION = '@connection',
|
||||
TRANSACTION = '@transaction',
|
||||
SCRIPTING = '@scripting'
|
||||
}
|
||||
|
||||
export type CommandRawReply = [
|
||||
name: string,
|
||||
arity: number,
|
||||
flags: Array<CommandFlags>,
|
||||
firstKeyIndex: number,
|
||||
lastKeyIndex: number,
|
||||
step: number,
|
||||
categories: Array<CommandCategories>
|
||||
];
|
||||
|
||||
export type CommandReply = {
|
||||
name: string,
|
||||
arity: number,
|
||||
flags: Set<CommandFlags>,
|
||||
firstKeyIndex: number,
|
||||
lastKeyIndex: number,
|
||||
step: number,
|
||||
categories: Set<CommandCategories>
|
||||
};
|
||||
|
||||
export function transformCommandReply(
|
||||
this: void,
|
||||
[name, arity, flags, firstKeyIndex, lastKeyIndex, step, categories]: CommandRawReply
|
||||
): CommandReply {
|
||||
return {
|
||||
name,
|
||||
arity,
|
||||
flags: new Set(flags),
|
||||
firstKeyIndex,
|
||||
lastKeyIndex,
|
||||
step,
|
||||
categories: new Set(categories)
|
||||
};
|
||||
}
|
||||
|
@@ -35,6 +35,10 @@ import * as CLUSTER_MEET from './CLUSTER_MEET';
|
||||
import * as CLUSTER_RESET from './CLUSTER_RESET';
|
||||
import * as CLUSTER_SETSLOT from './CLUSTER_SETSLOT';
|
||||
import * as CLUSTER_SLOTS from './CLUSTER_SLOTS';
|
||||
import * as COMMAND_COUNT from './COMMAND_COUNT';
|
||||
import * as COMMAND_GETKEYS from './COMMAND_GETKEYS';
|
||||
import * as COMMAND_INFO from './COMMAND_INFO';
|
||||
import * as COMMAND from './COMMAND';
|
||||
import * as CONFIG_GET from './CONFIG_GET';
|
||||
import * as CONFIG_RESETASTAT from './CONFIG_RESETSTAT';
|
||||
import * as CONFIG_REWRITE from './CONFIG_REWRITE';
|
||||
@@ -323,6 +327,14 @@ export default {
|
||||
clusterSetSlot: CLUSTER_SETSLOT,
|
||||
CLUSTER_SLOTS,
|
||||
clusterSlots: CLUSTER_SLOTS,
|
||||
COMMAND_COUNT,
|
||||
commandCount: COMMAND_COUNT,
|
||||
COMMAND_GETKEYS,
|
||||
commandGetKeys: COMMAND_GETKEYS,
|
||||
COMMAND_INFO,
|
||||
commandInfo: COMMAND_INFO,
|
||||
COMMAND,
|
||||
command: COMMAND,
|
||||
CONFIG_GET,
|
||||
configGet: CONFIG_GET,
|
||||
CONFIG_RESETASTAT,
|
||||
|
Reference in New Issue
Block a user