Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/client/lib/commands/RESET.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
20 changes: 20 additions & 0 deletions packages/client/lib/commands/RESET.ts
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 19 additions & 0 deletions packages/client/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-generated reset shadows critical client state management method

High Severity

Adding reset: RESET (and RESET) to the commands index causes attachConfig to place an auto-generated reset on the subclass prototype, which shadows RedisClient.prototype.reset(). The existing reset() method performs essential state management — calling #queue.reset() with special MONITOR/PubSub handling, disposing credentials subscriptions, re-running the handshake, and clearing #selectedDB, #monitorCallback, #dirtyWatch, and #watchEpoch. The auto-generated version just sends the raw RESET command via _executeCommand, leaving all client-side state stale. This also breaks the internal resetIfDirty() path used by RedisClientPool. Other commands with special client handling (MONITOR, SUBSCRIBE, etc.) are intentionally excluded from the commands index for this reason.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e2c8649. Configure here.

/**
* Constructs the REPLICAOF command
*
Expand Down