Skip to content

Commit 549a779

Browse files
committed
Merge branch 'master' of github.com:redis/node-redis
2 parents 3b36963 + 13ad249 commit 549a779

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

packages/client/lib/client/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,15 @@ export default class RedisClient<
619619
return this.#isolationPool.use(fn);
620620
}
621621

622-
multi(): RedisClientMultiCommandType<M, F, S> {
622+
MULTI(): RedisClientMultiCommandType<M, F, S> {
623623
return new (this as any).Multi(
624624
this.multiExecutor.bind(this),
625625
this.#options?.legacyMode
626626
);
627627
}
628628

629+
multi = this.MULTI;
630+
629631
async multiExecutor(
630632
commands: Array<RedisMultiQueuedCommand>,
631633
selectedDB?: number,

packages/client/lib/client/socket.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export default class RedisSocket extends EventEmitter {
105105
throw new Error('Socket already opened');
106106
}
107107

108+
this.#isOpen = true;
108109
return this.#connect();
109110
}
110111

@@ -116,7 +117,6 @@ export default class RedisSocket extends EventEmitter {
116117
}
117118

118119
try {
119-
this.#isOpen = true;
120120
this.#socket = await this.#createSocket();
121121
this.#writableNeedDrain = false;
122122
this.emit('connect');
@@ -142,7 +142,7 @@ export default class RedisSocket extends EventEmitter {
142142
await promiseTimeout(retryIn);
143143
}
144144
retries++;
145-
} while (!this.#isReady);
145+
} while (this.#isOpen && !this.#isReady);
146146
}
147147

148148
#createSocket(): Promise<net.Socket | tls.TLSSocket> {
@@ -203,6 +203,8 @@ export default class RedisSocket extends EventEmitter {
203203
this.#isReady = false;
204204
this.emit('error', err);
205205

206+
if (!this.#isOpen) return;
207+
206208
this.#connect(true).catch(() => {
207209
// the error was already emitted, silently ignore it
208210
});
@@ -219,14 +221,22 @@ export default class RedisSocket extends EventEmitter {
219221
}
220222

221223
disconnect(): void {
222-
if (!this.#socket) {
224+
if (!this.#isOpen) {
223225
throw new ClientClosedError();
224-
} else {
225-
this.#isOpen = this.#isReady = false;
226226
}
227227

228-
this.#socket.destroy();
229-
this.#socket = undefined;
228+
this.#isOpen = false;
229+
this.#disconnect();
230+
}
231+
232+
#disconnect(): void {
233+
this.#isReady = false;
234+
235+
if (this.#socket) {
236+
this.#socket.destroy();
237+
this.#socket = undefined;
238+
}
239+
230240
this.emit('end');
231241
}
232242

@@ -237,7 +247,7 @@ export default class RedisSocket extends EventEmitter {
237247

238248
this.#isOpen = false;
239249
await fn();
240-
this.disconnect();
250+
this.#disconnect();
241251
}
242252

243253
#isCorked = false;

packages/client/lib/cluster/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export default class RedisCluster<
224224
}
225225
}
226226

227-
multi(routing?: RedisCommandArgument): RedisClusterMultiCommandType<M, F, S> {
227+
MULTI(routing?: RedisCommandArgument): RedisClusterMultiCommandType<M, F, S> {
228228
return new this.#Multi(
229229
(commands: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, chainId?: symbol) => {
230230
return this.#execute(
@@ -237,6 +237,8 @@ export default class RedisCluster<
237237
);
238238
}
239239

240+
multi = this.MULTI;
241+
240242
getMasters(): Array<ClusterNode<M, F, S>> {
241243
return this.#slots.getMasters();
242244
}

0 commit comments

Comments
 (0)