From e2c86490bfb7be5e4ffa3073c505e5d345d6b839 Mon Sep 17 00:00:00 2001 From: sisyphusse1-ops Date: Fri, 15 May 2026 16:46:58 +0000 Subject: [PATCH] feat(client): add RESET command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds support for the RESET command which performs a full reset of the connection state — discarding any pending MULTI transaction, unsubscribing from every channel and pattern, exiting client tracking and monitor modes, selecting database 0 and resetting other connection state. Closes #1969 --- packages/client/lib/commands/RESET.spec.ts | 20 ++++++++++++++++++++ packages/client/lib/commands/RESET.ts | 20 ++++++++++++++++++++ packages/client/lib/commands/index.ts | 19 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 packages/client/lib/commands/RESET.spec.ts create mode 100644 packages/client/lib/commands/RESET.ts diff --git a/packages/client/lib/commands/RESET.spec.ts b/packages/client/lib/commands/RESET.spec.ts new file mode 100644 index 0000000000..50b782f71e --- /dev/null +++ b/packages/client/lib/commands/RESET.spec.ts @@ -0,0 +1,20 @@ +import { strict as assert } from 'node:assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import RESET from './RESET'; +import { parseArgs } from './generic-transformers'; + +describe('RESET', () => { + it('transformArguments', () => { + assert.deepEqual( + parseArgs(RESET), + ['RESET'] + ); + }); + + testUtils.testWithClient('client.reset', async client => { + assert.equal( + await client.reset(), + 'RESET' + ); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/RESET.ts b/packages/client/lib/commands/RESET.ts new file mode 100644 index 0000000000..1a5de4237c --- /dev/null +++ b/packages/client/lib/commands/RESET.ts @@ -0,0 +1,20 @@ +import { CommandParser } from '../client/parser'; +import { SimpleStringReply, Command } from '../RESP/types'; + +export default { + NOT_KEYED_COMMAND: true, + IS_READ_ONLY: true, + /** + * Performs a full reset of the connection state: discards any pending + * transaction (`MULTI`), unsubscribes from every channel/pattern, exits + * client tracking and monitor modes, selects database `0`, and resets + * `CLIENT TRACKINGINFO` and `CLIENT REPLY` state, among others. + * + * @param parser - The command parser + * @see https://redis.io/commands/reset/ + */ + parseCommand(parser: CommandParser) { + parser.push('RESET'); + }, + transformReply: undefined as unknown as () => SimpleStringReply<'RESET'> +} as const satisfies Command; diff --git a/packages/client/lib/commands/index.ts b/packages/client/lib/commands/index.ts index 0c60cb58d5..4ec7888b37 100644 --- a/packages/client/lib/commands/index.ts +++ b/packages/client/lib/commands/index.ts @@ -238,6 +238,7 @@ import RANDOMKEY from './RANDOMKEY'; import READONLY from './READONLY'; import RENAME from './RENAME'; import RENAMENX from './RENAMENX'; +import RESET from './RESET'; import REPLICAOF from './REPLICAOF'; import RESTORE_ASKING from './RESTORE-ASKING'; import RESTORE from './RESTORE'; @@ -3487,6 +3488,24 @@ export default { * @see https://redis.io/commands/renamenx/ */ renameNX: RENAMENX, + /** + * Performs a full reset of the connection state: discards any pending + * transaction (`MULTI`), unsubscribes from every channel/pattern, exits + * client tracking and monitor modes, selects database `0`, and resets + * `CLIENT TRACKINGINFO` and `CLIENT REPLY` state, among others. + * + * @see https://redis.io/commands/reset/ + */ + RESET, + /** + * Performs a full reset of the connection state: discards any pending + * transaction (`MULTI`), unsubscribes from every channel/pattern, exits + * client tracking and monitor modes, selects database `0`, and resets + * `CLIENT TRACKINGINFO` and `CLIENT REPLY` state, among others. + * + * @see https://redis.io/commands/reset/ + */ + reset: RESET, /** * Constructs the REPLICAOF command *