From 46b831c92282d16d5b224effa20cf8dc6002fd8c Mon Sep 17 00:00:00 2001 From: Leibale Eidelman Date: Mon, 31 Jan 2022 08:35:35 -0500 Subject: [PATCH] fix #1864 - cluster.quit (#1886) --- packages/client/lib/cluster/cluster-slots.ts | 19 +++++++++++++++---- packages/client/lib/cluster/index.ts | 4 ++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/client/lib/cluster/cluster-slots.ts b/packages/client/lib/cluster/cluster-slots.ts index bcf95390ce..044cedf56a 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 4f2f3f98d3..123400dd7e 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(); }