diff --git a/packages/client/lib/client/commands.ts b/packages/client/lib/client/commands.ts index 0d9f63b003..c227f7f29b 100644 --- a/packages/client/lib/client/commands.ts +++ b/packages/client/lib/client/commands.ts @@ -31,6 +31,7 @@ import * as CLUSTER_RESET from '../commands/CLUSTER_RESET'; import * as CLUSTER_SETSLOT from '../commands/CLUSTER_SETSLOT'; import * as CLUSTER_SLOTS from '../commands/CLUSTER_SLOTS'; import * as COMMAND_COUNT from '../commands/COMMAND_COUNT'; +import * as COMMAND_DOCS from '../commands/COMMAND_DOCS'; import * as COMMAND_GETKEYS from '../commands/COMMAND_GETKEYS'; import * as COMMAND_INFO from '../commands/COMMAND_INFO'; import * as COMMAND_LIST from '../commands/COMMAND_LIST'; @@ -148,6 +149,8 @@ export default { clusterSlots: CLUSTER_SLOTS, COMMAND_COUNT, commandCount: COMMAND_COUNT, + COMMAND_DOCS, + commandDocs: COMMAND_DOCS, COMMAND_GETKEYS, commandGetKeys: COMMAND_GETKEYS, COMMAND_INFO, diff --git a/packages/client/lib/commands/COMMAND_DOCS.spec.ts b/packages/client/lib/commands/COMMAND_DOCS.spec.ts new file mode 100644 index 0000000000..75688452d4 --- /dev/null +++ b/packages/client/lib/commands/COMMAND_DOCS.spec.ts @@ -0,0 +1,30 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './COMMAND_DOCS'; + +describe('COMMAND DOCS', () => { + testUtils.isVersionGreaterThanHook([7, 0]); + + it('transformArguments', () => { + assert.deepEqual( + transformArguments('SORT'), + ['COMMAND', 'DOCS', 'SORT'] + ); + }); + + testUtils.testWithClient('client.commandDocs', async client => { + assert.deepEqual( + await client.commandDocs('sort'), + [[ + 'sort', + { + summary: 'Sort the elements in a list, set or sorted set', + since: '1.0.0', + group: 'generic', + complexity: 'O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).', + history: null + } + ]] + ); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/COMMAND_DOCS.ts b/packages/client/lib/commands/COMMAND_DOCS.ts new file mode 100644 index 0000000000..c1eed4e326 --- /dev/null +++ b/packages/client/lib/commands/COMMAND_DOCS.ts @@ -0,0 +1,38 @@ +import { RedisCommandArguments } from '.'; +import { pushVerdictArguments } from './generic-transformers'; + +export const IS_READ_ONLY = true; + +export function transformArguments(keys: string | Array): RedisCommandArguments { + return pushVerdictArguments(['COMMAND', 'DOCS'], keys); +} + +type CommandDocumentation = { + summary: string; + since: string; + group: string; + complexity: string; + history?: Array; +}; + +type CommandDocsReply = Array<[CommandName: string, CommandDocumentation: CommandDocumentation]>; + +export function transformReply(rawReply: Array): CommandDocsReply { + const replyArray:CommandDocsReply = [] + + for (let i = 0; i < rawReply.length; i++) { + + replyArray.push([ + rawReply[i++], // The name of the command + { + summary: rawReply[i][1], + since: rawReply[i][3], + group: rawReply[i][5], + complexity: rawReply[i][7], + history: rawReply[i][8] == 'history' ? rawReply[i][9] : null + } + ]); + } + + return replyArray; +}