diff --git a/packages/client/lib/cluster/cluster-slots.ts b/packages/client/lib/cluster/cluster-slots.ts index bcf95390ce3..044cedf56a8 100644 --- a/packages/client/lib/cluster/cluster-slots.ts +++ b/packages/client/lib/cluster/cluster-slots.ts @@ -232,10 +232,21 @@ export default class RedisClusterSlots { - await Promise.all( - [...this.#nodeByUrl.values()].map(({ client }) => client.disconnect()) - ); + quit(): Promise { + return this.#destroy(client => client.quit()); + } + + disconnect(): Promise { + return this.#destroy(client => client.disconnect()); + } + + async #destroy(fn: (client: RedisClientType) => Promise): Promise { + const promises = []; + for (const { client } of this.#nodeByUrl.values()) { + promises.push(fn(client)); + } + + await Promise.all(promises); this.#nodeByUrl.clear(); this.#slots.splice(0); diff --git a/packages/client/lib/cluster/index.ts b/packages/client/lib/cluster/index.ts index 4f2f3f98d3e..123400dd7e5 100644 --- a/packages/client/lib/cluster/index.ts +++ b/packages/client/lib/cluster/index.ts @@ -191,6 +191,10 @@ export default class RedisCluster { + return this.#slots.quit(); + } + disconnect(): Promise { return this.#slots.disconnect(); }