1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

Support COMMAND DOCS

This commit is contained in:
Avital-Fine
2022-03-16 14:27:33 +01:00
parent be51abe347
commit 4fa53a88b1
3 changed files with 71 additions and 0 deletions

View File

@@ -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);
});

View File

@@ -0,0 +1,38 @@
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export const IS_READ_ONLY = true;
export function transformArguments(keys: string | Array<string>): RedisCommandArguments {
return pushVerdictArguments(['COMMAND', 'DOCS'], keys);
}
type CommandDocumentation = {
summary: string;
since: string;
group: string;
complexity: string;
history?: Array<string>;
};
type CommandDocsReply = Array<[CommandName: string, CommandDocumentation: CommandDocumentation]>;
export function transformReply(rawReply: Array<any>): 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;
}