You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-12-11 09:22:35 +03:00
feat: add LATENCY_RESET command (#3047)
This commit is contained in:
104
packages/client/lib/commands/LATENCY_RESET.spec.ts
Normal file
104
packages/client/lib/commands/LATENCY_RESET.spec.ts
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
import { strict as assert } from 'node:assert';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import LATENCY_RESET, { LATENCY_EVENTS } from './LATENCY_RESET';
|
||||||
|
import { parseArgs } from './generic-transformers';
|
||||||
|
|
||||||
|
describe('LATENCY RESET', function () {
|
||||||
|
|
||||||
|
|
||||||
|
it('transformArguments with no events', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
parseArgs(LATENCY_RESET),
|
||||||
|
[
|
||||||
|
'LATENCY',
|
||||||
|
'RESET'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('transformArguments with one event', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
parseArgs(LATENCY_RESET, LATENCY_EVENTS.COMMAND),
|
||||||
|
[
|
||||||
|
'LATENCY',
|
||||||
|
'RESET',
|
||||||
|
'command'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('transformArguments with multiple events', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
parseArgs(LATENCY_RESET, LATENCY_EVENTS.COMMAND, LATENCY_EVENTS.FORK),
|
||||||
|
[
|
||||||
|
'LATENCY',
|
||||||
|
'RESET',
|
||||||
|
'command',
|
||||||
|
'fork'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.latencyReset', async client => {
|
||||||
|
|
||||||
|
await client.configSet('latency-monitor-threshold', '1');
|
||||||
|
|
||||||
|
|
||||||
|
await client.sendCommand(['DEBUG', 'SLEEP', '0.1']);
|
||||||
|
|
||||||
|
|
||||||
|
const latestLatencyBeforeReset = await client.latencyLatest();
|
||||||
|
assert.ok(latestLatencyBeforeReset.length > 0, 'Expected latency events to be recorded before first reset.');
|
||||||
|
assert.equal(latestLatencyBeforeReset[0][0], 'command', 'Expected "command" event to be recorded.');
|
||||||
|
assert.ok(Number(latestLatencyBeforeReset[0][2]) >= 100, 'Expected latest latency for "command" to be at least 100ms.');
|
||||||
|
|
||||||
|
|
||||||
|
const replyAll = await client.latencyReset();
|
||||||
|
|
||||||
|
assert.equal(typeof replyAll, 'number');
|
||||||
|
assert.ok(replyAll >= 0);
|
||||||
|
|
||||||
|
|
||||||
|
const latestLatencyAfterAllReset = await client.latencyLatest();
|
||||||
|
assert.deepEqual(latestLatencyAfterAllReset, [], 'Expected no latency events after resetting all.');
|
||||||
|
|
||||||
|
|
||||||
|
await client.sendCommand(['DEBUG', 'SLEEP', '0.05']);
|
||||||
|
const latestLatencyBeforeSpecificReset = await client.latencyLatest();
|
||||||
|
assert.ok(latestLatencyBeforeSpecificReset.length > 0, 'Expected latency events before specific reset.');
|
||||||
|
|
||||||
|
|
||||||
|
const replySpecific = await client.latencyReset(LATENCY_EVENTS.COMMAND);
|
||||||
|
assert.equal(typeof replySpecific, 'number');
|
||||||
|
assert.ok(replySpecific >= 0);
|
||||||
|
|
||||||
|
|
||||||
|
const latestLatencyAfterSpecificReset = await client.latencyLatest();
|
||||||
|
assert.deepEqual(latestLatencyAfterSpecificReset, [], 'Expected no latency events after specific reset of "command".');
|
||||||
|
|
||||||
|
|
||||||
|
await client.sendCommand(['DEBUG', 'SLEEP', '0.02']);
|
||||||
|
|
||||||
|
|
||||||
|
const latestLatencyBeforeMultipleReset = await client.latencyLatest();
|
||||||
|
assert.ok(latestLatencyBeforeMultipleReset.length > 0, 'Expected latency events before multiple reset.');
|
||||||
|
|
||||||
|
|
||||||
|
const replyMultiple = await client.latencyReset(LATENCY_EVENTS.COMMAND, LATENCY_EVENTS.FORK);
|
||||||
|
assert.equal(typeof replyMultiple, 'number');
|
||||||
|
assert.ok(replyMultiple >= 0);
|
||||||
|
|
||||||
|
const latestLatencyAfterMultipleReset = await client.latencyLatest();
|
||||||
|
assert.deepEqual(latestLatencyAfterMultipleReset, [], 'Expected no latency events after multiple specified resets.');
|
||||||
|
|
||||||
|
}, {
|
||||||
|
|
||||||
|
...GLOBAL.SERVERS.OPEN,
|
||||||
|
clientOptions: {
|
||||||
|
socket: {
|
||||||
|
connectTimeout: 300000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
24
packages/client/lib/commands/LATENCY_RESET.ts
Normal file
24
packages/client/lib/commands/LATENCY_RESET.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { CommandParser } from '../client/parser';
|
||||||
|
import { Command } from '../RESP/types';
|
||||||
|
import { LATENCY_EVENTS, LatencyEvent } from './LATENCY_GRAPH';
|
||||||
|
|
||||||
|
export { LATENCY_EVENTS, LatencyEvent };
|
||||||
|
|
||||||
|
export default {
|
||||||
|
NOT_KEYED_COMMAND: true,
|
||||||
|
IS_READ_ONLY: false,
|
||||||
|
/**
|
||||||
|
* Constructs the LATENCY RESET command
|
||||||
|
* * @param parser - The command parser
|
||||||
|
* @param events - The latency events to reset. If not specified, all events are reset.
|
||||||
|
* @see https://redis.io/commands/latency-reset/
|
||||||
|
*/
|
||||||
|
parseCommand(parser: CommandParser, ...events: Array<LatencyEvent>) {
|
||||||
|
const args = ['LATENCY', 'RESET'];
|
||||||
|
if (events.length > 0) {
|
||||||
|
args.push(...events);
|
||||||
|
}
|
||||||
|
parser.push(...args);
|
||||||
|
},
|
||||||
|
transformReply: undefined as unknown as () => number
|
||||||
|
} as const satisfies Command;
|
||||||
@@ -171,6 +171,7 @@ import LATENCY_DOCTOR from './LATENCY_DOCTOR';
|
|||||||
import LATENCY_GRAPH from './LATENCY_GRAPH';
|
import LATENCY_GRAPH from './LATENCY_GRAPH';
|
||||||
import LATENCY_HISTORY from './LATENCY_HISTORY';
|
import LATENCY_HISTORY from './LATENCY_HISTORY';
|
||||||
import LATENCY_LATEST from './LATENCY_LATEST';
|
import LATENCY_LATEST from './LATENCY_LATEST';
|
||||||
|
import LATENCY_RESET from './LATENCY_RESET';
|
||||||
import LCS_IDX_WITHMATCHLEN from './LCS_IDX_WITHMATCHLEN';
|
import LCS_IDX_WITHMATCHLEN from './LCS_IDX_WITHMATCHLEN';
|
||||||
import LCS_IDX from './LCS_IDX';
|
import LCS_IDX from './LCS_IDX';
|
||||||
import LCS_LEN from './LCS_LEN';
|
import LCS_LEN from './LCS_LEN';
|
||||||
@@ -706,6 +707,8 @@ export default {
|
|||||||
latencyHistory: LATENCY_HISTORY,
|
latencyHistory: LATENCY_HISTORY,
|
||||||
LATENCY_LATEST,
|
LATENCY_LATEST,
|
||||||
latencyLatest: LATENCY_LATEST,
|
latencyLatest: LATENCY_LATEST,
|
||||||
|
LATENCY_RESET,
|
||||||
|
latencyReset: LATENCY_RESET,
|
||||||
LCS_IDX_WITHMATCHLEN,
|
LCS_IDX_WITHMATCHLEN,
|
||||||
lcsIdxWithMatchLen: LCS_IDX_WITHMATCHLEN,
|
lcsIdxWithMatchLen: LCS_IDX_WITHMATCHLEN,
|
||||||
LCS_IDX,
|
LCS_IDX,
|
||||||
|
|||||||
Reference in New Issue
Block a user