Skip to content

Commit 62ac8b7

Browse files
authored
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
1 parent ca91718 commit 62ac8b7

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

docs/v5.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ RESP3 uses a different mechanism for handling Pub/Sub messages. Instead of modif
4242

4343
## Known Limitations
4444

45-
### Unstable Module Commands
45+
### Unstable Commands
4646

47-
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:
47+
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:
4848

4949
```javascript
5050
const client = createClient({

packages/client/lib/commander.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ export function attachConfig<
3838
Class: any = class extends BaseClass {};
3939

4040
for (const [name, command] of Object.entries(commands)) {
41-
Class.prototype[name] = createCommand(command, RESP);
41+
if (config?.RESP == 3 && command.unstableResp3 && !config.unstableResp3) {
42+
Class.prototype[name] = throwResp3SearchModuleUnstableError;
43+
} else {
44+
Class.prototype[name] = createCommand(command, RESP);
45+
}
4246
}
4347

4448
if (config?.modules) {

packages/client/lib/commands/XREAD.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,37 @@ describe('XREAD', () => {
131131
client: GLOBAL.SERVERS.OPEN,
132132
cluster: GLOBAL.CLUSTERS.OPEN
133133
});
134+
135+
testUtils.testWithClient('client.xRead should throw with resp3 and unstableResp3: false', async client => {
136+
assert.throws(
137+
() => client.xRead({
138+
key: 'key',
139+
id: '0-0'
140+
}),
141+
{
142+
message: 'Some RESP3 results for Redis Query Engine responses may change. Refer to the readme for guidance'
143+
}
144+
);
145+
}, {
146+
...GLOBAL.SERVERS.OPEN,
147+
clientOptions: {
148+
RESP: 3
149+
}
150+
});
151+
152+
testUtils.testWithClient('client.xRead should not throw with resp3 and unstableResp3: true', async client => {
153+
assert.doesNotThrow(
154+
() => client.xRead({
155+
key: 'key',
156+
id: '0-0'
157+
})
158+
);
159+
}, {
160+
...GLOBAL.SERVERS.OPEN,
161+
clientOptions: {
162+
RESP: 3,
163+
unstableResp3: true
164+
}
165+
});
166+
134167
});

packages/client/lib/commands/XREADGROUP.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,36 @@ describe('XREADGROUP', () => {
155155
client: GLOBAL.SERVERS.OPEN,
156156
cluster: GLOBAL.CLUSTERS.OPEN
157157
});
158+
159+
testUtils.testWithClient('client.xReadGroup should throw with resp3 and unstableResp3: false', async client => {
160+
assert.throws(
161+
() => client.xReadGroup('group', 'consumer', {
162+
key: 'key',
163+
id: '>'
164+
}),
165+
{
166+
message: 'Some RESP3 results for Redis Query Engine responses may change. Refer to the readme for guidance'
167+
}
168+
);
169+
}, {
170+
...GLOBAL.SERVERS.OPEN,
171+
clientOptions: {
172+
RESP: 3
173+
}
174+
});
175+
176+
testUtils.testWithClient('client.xReadGroup should not throw with resp3 and unstableResp3: true', async client => {
177+
assert.doesNotThrow(
178+
() => client.xReadGroup('group', 'consumer', {
179+
key: 'key',
180+
id: '>'
181+
})
182+
);
183+
}, {
184+
...GLOBAL.SERVERS.OPEN,
185+
clientOptions: {
186+
RESP: 3,
187+
unstableResp3: true
188+
}
189+
});
158190
});

0 commit comments

Comments
 (0)