Skip to content

fix(client): make unstable cmds throw #2990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
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
4 changes: 2 additions & 2 deletions docs/v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 5 additions & 1 deletion packages/client/lib/commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

@nkaradzhov I just remembered that I saw this piece of code which was supposed to attach a command that throws an error. Maybe we can fix that code instead.

Copy link
Collaborator Author

@nkaradzhov nkaradzhov Jun 5, 2025

Choose a reason for hiding this comment

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

@bobymicroby this is working properly. The problem is that it is executed only for module commands. And we have XREAD and XREADGROUP as part of the main client. So we should add the same logic in the place we attach the core functions as well

Copy link
Member

Choose a reason for hiding this comment

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

got it

Class.prototype[name] = throwResp3SearchModuleUnstableError;
} else {
Class.prototype[name] = createCommand(command, RESP);
}
}

if (config?.modules) {
Expand Down
33 changes: 33 additions & 0 deletions packages/client/lib/commands/XREAD.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});

});
32 changes: 32 additions & 0 deletions packages/client/lib/commands/XREADGROUP.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
});
Loading