1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

fix FUNCTION STATS

This commit is contained in:
Leibale
2023-10-02 14:04:02 -04:00
parent 867c436bb5
commit 52772858b4
2 changed files with 81 additions and 98 deletions

View File

@@ -1,25 +1,25 @@
// import { strict as assert } from 'node:assert'; import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
// import { transformArguments } from './FUNCTION_STATS'; import FUNCTION_STATS from './FUNCTION_STATS';
// describe('FUNCTION STATS', () => { describe('FUNCTION STATS', () => {
// testUtils.isVersionGreaterThanHook([7]); testUtils.isVersionGreaterThanHook([7]);
// it('transformArguments', () => { it('transformArguments', () => {
// assert.deepEqual( assert.deepEqual(
// transformArguments(), FUNCTION_STATS.transformArguments(),
// ['FUNCTION', 'STATS'] ['FUNCTION', 'STATS']
// ); );
// }); });
// testUtils.testWithClient('client.functionStats', async client => { testUtils.testWithClient('client.functionStats', async client => {
// const stats = await client.functionStats(); const stats = await client.functionStats();
// assert.equal(stats.runningScript, null); assert.equal(stats.running_script, null);
// assert.equal(typeof stats.engines, 'object'); assert.equal(typeof stats.engines, 'object');
// for (const [engine, { librariesCount, functionsCount }] of Object.entries(stats.engines)) { for (const [engine, { libraries_count, functions_count }] of Object.entries(stats.engines)) {
// assert.equal(typeof engine, 'string'); assert.equal(typeof engine, 'string');
// assert.equal(typeof librariesCount, 'number'); assert.equal(typeof libraries_count, 'number');
// assert.equal(typeof functionsCount, 'number'); assert.equal(typeof functions_count, 'number');
// } }
// }, GLOBAL.SERVERS.OPEN); }, GLOBAL.SERVERS.OPEN);
// }); });

View File

@@ -1,87 +1,70 @@
// // import { RedisCommandArguments } from '.'; import { Command, TuplesToMapReply, BlobStringReply, NullReply, NumberReply, MapReply, Resp2Reply, UnwrapReply } from '../RESP/types';
import { isNullReply } from './generic-transformers';
// // export function transformArguments(): RedisCommandArguments { type RunningScript = NullReply | TuplesToMapReply<[
// // return ['FUNCTION', 'STATS']; [BlobStringReply<'name'>, BlobStringReply],
// // } [BlobStringReply<'command'>, BlobStringReply],
[BlobStringReply<'duration_ms'>, NumberReply]
]>;
// // type FunctionStatsRawReply = [ type Engine = TuplesToMapReply<[
// // 'running_script', [BlobStringReply<'libraries_count'>, NumberReply],
// // null | [ [BlobStringReply<'functions_count'>, NumberReply]
// // 'name', ]>;
// // string,
// // 'command',
// // string,
// // 'duration_ms',
// // number
// // ],
// // 'engines',
// // Array<any> // "flat tuples" (there is no way to type that)
// // // ...[string, [
// // // 'libraries_count',
// // // number,
// // // 'functions_count',
// // // number
// // // ]]
// // ];
// // interface FunctionStatsReply { type Engines = MapReply<BlobStringReply, Engine>;
// // runningScript: null | {
// // name: string;
// // command: string;
// // durationMs: number;
// // };
// // engines: Record<string, {
// // librariesCount: number;
// // functionsCount: number;
// // }>;
// // }
// // export function transformReply(reply: FunctionStatsRawReply): FunctionStatsReply { type FunctionStatsReply = TuplesToMapReply<[
// // const engines = Object.create(null); [BlobStringReply<'running_script'>, RunningScript],
// // for (let i = 0; i < reply[3].length; i++) { [BlobStringReply<'engines'>, Engines]
// // engines[reply[3][i]] = { ]>;
// // librariesCount: reply[3][++i][1],
// // functionsCount: reply[3][i][3]
// // };
// // }
// // return { export default {
// // runningScript: reply[1] === null ? null : { IS_READ_ONLY: true,
// // name: reply[1][1], FIRST_KEY_INDEX: undefined,
// // command: reply[1][3], transformArguments() {
// // durationMs: reply[1][5] return ['FUNCTION', 'STATS'];
// // }, },
// // engines transformReply: {
// // }; 2: (reply: UnwrapReply<Resp2Reply<FunctionStatsReply>>) => {
// // } return {
running_script: transformRunningScript(reply[1]),
engines: transformEngines(reply[3])
};
},
3: undefined as unknown as () => FunctionStatsReply
}
} as const satisfies Command;
function transformRunningScript(reply: Resp2Reply<RunningScript>) {
if (isNullReply(reply)) {
return null;
}
// // #!LUA name=math \n redis.register_function{ function_name = "square", callback = function(keys, args) return args[1] * args[1] end, flags = { "no-writes" } } const unwraped = reply as unknown as UnwrapReply<typeof reply>;
return {
name: unwraped[1],
command: unwraped[3],
duration_ms: unwraped[5]
};
}
// import { Command, TuplesToMapReply, BlobStringReply, NullReply, NumberReply, MapReply } from '../RESP/types'; function transformEngines(reply: Resp2Reply<Engines>) {
const unwraped = reply as unknown as UnwrapReply<typeof reply>;
// type FunctionStatsReply = TuplesToMapReply<[ const engines: Record<string, {
// [BlobStringReply<'running_script'>, NullReply | TuplesToMapReply<[ libraries_count: NumberReply;
// [BlobStringReply<'name'>, BlobStringReply], functions_count: NumberReply;
// [BlobStringReply<'command'>, BlobStringReply], }> = Object.create(null);
// [BlobStringReply<'duration_ms'>, NumberReply] for (let i = 0; i < unwraped.length; i++) {
// ]>], const name = unwraped[i] as BlobStringReply,
// [BlobStringReply<'engines'>, MapReply<BlobStringReply, TuplesToMapReply<[ stats = unwraped[++i] as Resp2Reply<Engine>,
// [BlobStringReply<'libraries_count'>, NumberReply], unwrapedStats = stats as unknown as UnwrapReply<typeof stats>;
// [BlobStringReply<'functions_count'>, NumberReply] engines[name.toString()] = {
// ]>>] libraries_count: unwrapedStats[1],
// ]>; functions_count: unwrapedStats[3]
};
}
// export default { return engines;
// IS_READ_ONLY: true, }
// FIRST_KEY_INDEX: undefined,
// transformArguments() {
// return ['FUNCTION', 'STATS'];
// },
// transformReply: {
// 2: (reply) => {
// },
// 3: undefined as unknown as () =>
// }
// } as const satisfies Command;