From 62ac8b7c32473b9d0e45cbb628d05a910bc00a5f Mon Sep 17 00:00:00 2001 From: Nikolay Karadzhov Date: Fri, 6 Jun 2025 15:38:52 +0300 Subject: [PATCH] fix(client): make unstable cmds throw (#2990) As per the docs, unstableResp3 commands should throw when client is created with { RESP: 3, unstableResp3: false|undefined } fixes #2989 --- docs/v5.md | 4 +-- packages/client/lib/commander.ts | 6 +++- packages/client/lib/commands/XREAD.spec.ts | 33 +++++++++++++++++++ .../client/lib/commands/XREADGROUP.spec.ts | 32 ++++++++++++++++++ 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/docs/v5.md b/docs/v5.md index 1784ae5bd7..15ef67c14e 100644 --- a/docs/v5.md +++ b/docs/v5.md @@ -42,9 +42,9 @@ RESP3 uses a different mechanism for handling Pub/Sub messages. Instead of modif ## Known Limitations -### Unstable Module Commands +### Unstable Commands -Some Redis module commands have unstable RESP3 transformations. These commands will throw an error when used with RESP3 unless you explicitly opt in to using them by setting `unstableResp3: true` in your client configuration: +Some Redis commands have unstable RESP3 transformations. These commands will throw an error when used with RESP3 unless you explicitly opt in to using them by setting `unstableResp3: true` in your client configuration: ```javascript const client = createClient({ diff --git a/packages/client/lib/commander.ts b/packages/client/lib/commander.ts index 6e5a2687cb..cfdf39526c 100644 --- a/packages/client/lib/commander.ts +++ b/packages/client/lib/commander.ts @@ -38,7 +38,11 @@ export function attachConfig< Class: any = class extends BaseClass {}; for (const [name, command] of Object.entries(commands)) { - Class.prototype[name] = createCommand(command, RESP); + if (config?.RESP == 3 && command.unstableResp3 && !config.unstableResp3) { + Class.prototype[name] = throwResp3SearchModuleUnstableError; + } else { + Class.prototype[name] = createCommand(command, RESP); + } } if (config?.modules) { diff --git a/packages/client/lib/commands/XREAD.spec.ts b/packages/client/lib/commands/XREAD.spec.ts index bb72c96497..0edcfe4311 100644 --- a/packages/client/lib/commands/XREAD.spec.ts +++ b/packages/client/lib/commands/XREAD.spec.ts @@ -131,4 +131,37 @@ describe('XREAD', () => { client: GLOBAL.SERVERS.OPEN, cluster: GLOBAL.CLUSTERS.OPEN }); + + testUtils.testWithClient('client.xRead should throw with resp3 and unstableResp3: false', async client => { + assert.throws( + () => client.xRead({ + key: 'key', + id: '0-0' + }), + { + message: 'Some RESP3 results for Redis Query Engine responses may change. Refer to the readme for guidance' + } + ); + }, { + ...GLOBAL.SERVERS.OPEN, + clientOptions: { + RESP: 3 + } + }); + + testUtils.testWithClient('client.xRead should not throw with resp3 and unstableResp3: true', async client => { + assert.doesNotThrow( + () => client.xRead({ + key: 'key', + id: '0-0' + }) + ); + }, { + ...GLOBAL.SERVERS.OPEN, + clientOptions: { + RESP: 3, + unstableResp3: true + } + }); + }); diff --git a/packages/client/lib/commands/XREADGROUP.spec.ts b/packages/client/lib/commands/XREADGROUP.spec.ts index 085a67bc9b..acc7cc2dea 100644 --- a/packages/client/lib/commands/XREADGROUP.spec.ts +++ b/packages/client/lib/commands/XREADGROUP.spec.ts @@ -155,4 +155,36 @@ describe('XREADGROUP', () => { client: GLOBAL.SERVERS.OPEN, cluster: GLOBAL.CLUSTERS.OPEN }); + + testUtils.testWithClient('client.xReadGroup should throw with resp3 and unstableResp3: false', async client => { + assert.throws( + () => client.xReadGroup('group', 'consumer', { + key: 'key', + id: '>' + }), + { + message: 'Some RESP3 results for Redis Query Engine responses may change. Refer to the readme for guidance' + } + ); + }, { + ...GLOBAL.SERVERS.OPEN, + clientOptions: { + RESP: 3 + } + }); + + testUtils.testWithClient('client.xReadGroup should not throw with resp3 and unstableResp3: true', async client => { + assert.doesNotThrow( + () => client.xReadGroup('group', 'consumer', { + key: 'key', + id: '>' + }) + ); + }, { + ...GLOBAL.SERVERS.OPEN, + clientOptions: { + RESP: 3, + unstableResp3: true + } + }); });