Skip to content

Commit aff3c9b

Browse files
committed
Fix multi.exec with empty queue and previous watch
When calling exec on a multi instance which you did not use, no command is sent currently. This is a problem for watched keys, because no EXEC means no unwatch, which might cause hard-to-debug problems. Proposed Fix: Sending UNWATCH
1 parent 1be8422 commit aff3c9b

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

packages/client/lib/client/multi-command.ts

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ export default class RedisClientMultiCommand {
171171
}
172172

173173
const commands = this.#multi.exec();
174-
if (!commands) return [];
175174

176175
return this.#multi.handleExecReplies(
177176
await this.#executor(

packages/client/lib/cluster/multi-command.ts

-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ export default class RedisClusterMultiCommand {
121121
}
122122

123123
const commands = this.#multi.exec();
124-
if (!commands) return [];
125124

126125
return this.#multi.handleExecReplies(
127126
await this.#executor(commands, this.#firstKey, RedisMultiCommand.generateChainId())

packages/client/lib/multi-command.spec.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ describe('Multi Command', () => {
4646
});
4747

4848
describe('exec', () => {
49-
it('undefined', () => {
49+
it('without commands', () => {
5050
assert.equal(
5151
new RedisMultiCommand().exec(),
52-
undefined
52+
[
53+
{ args: ['UNWATCH'] }
54+
]
5355
);
5456
});
5557

56-
it('Array', () => {
58+
it('with commands', () => {
5759
const multi = new RedisMultiCommand();
5860
multi.addCommand(['PING']);
5961

packages/client/lib/multi-command.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ export default class RedisMultiCommand {
6969
return transformedArguments;
7070
}
7171

72-
exec(): undefined | Array<RedisMultiQueuedCommand> {
72+
exec(): Array<RedisMultiQueuedCommand> {
7373
if (!this.queue.length) {
74-
return;
74+
return [{ args: ['UNWATCH'] }];
7575
}
7676

7777
return [

0 commit comments

Comments
 (0)