Skip to content

Commit 46b831c

Browse files
authored
fix #1864 - cluster.quit (#1886)
1 parent 8160fa7 commit 46b831c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

packages/client/lib/cluster/cluster-slots.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,21 @@ export default class RedisClusterSlots<M extends RedisModules, S extends RedisSc
232232
return this.#nodeByUrl.get(url);
233233
}
234234

235-
async disconnect(): Promise<void> {
236-
await Promise.all(
237-
[...this.#nodeByUrl.values()].map(({ client }) => client.disconnect())
238-
);
235+
quit(): Promise<void> {
236+
return this.#destroy(client => client.quit());
237+
}
238+
239+
disconnect(): Promise<void> {
240+
return this.#destroy(client => client.disconnect());
241+
}
242+
243+
async #destroy(fn: (client: RedisClientType<M, S>) => Promise<unknown>): Promise<void> {
244+
const promises = [];
245+
for (const { client } of this.#nodeByUrl.values()) {
246+
promises.push(fn(client));
247+
}
248+
249+
await Promise.all(promises);
239250

240251
this.#nodeByUrl.clear();
241252
this.#slots.splice(0);

packages/client/lib/cluster/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ export default class RedisCluster<M extends RedisModules, S extends RedisScripts
191191
return this.#slots.getSlotMaster(slot);
192192
}
193193

194+
quit(): Promise<void> {
195+
return this.#slots.quit();
196+
}
197+
194198
disconnect(): Promise<void> {
195199
return this.#slots.disconnect();
196200
}

0 commit comments

Comments
 (0)