Skip to content

Commit

Permalink
fix #1864 - cluster.quit (#1886)
Browse files Browse the repository at this point in the history
  • Loading branch information
leibale authored Jan 31, 2022
1 parent 8160fa7 commit 46b831c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/client/lib/cluster/cluster-slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,21 @@ export default class RedisClusterSlots<M extends RedisModules, S extends RedisSc
return this.#nodeByUrl.get(url);
}

async disconnect(): Promise<void> {
await Promise.all(
[...this.#nodeByUrl.values()].map(({ client }) => client.disconnect())
);
quit(): Promise<void> {
return this.#destroy(client => client.quit());
}

disconnect(): Promise<void> {
return this.#destroy(client => client.disconnect());
}

async #destroy(fn: (client: RedisClientType<M, S>) => Promise<unknown>): Promise<void> {
const promises = [];
for (const { client } of this.#nodeByUrl.values()) {
promises.push(fn(client));
}

await Promise.all(promises);

this.#nodeByUrl.clear();
this.#slots.splice(0);
Expand Down
4 changes: 4 additions & 0 deletions packages/client/lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export default class RedisCluster<M extends RedisModules, S extends RedisScripts
return this.#slots.getSlotMaster(slot);
}

quit(): Promise<void> {
return this.#slots.quit();
}

disconnect(): Promise<void> {
return this.#slots.disconnect();
}
Expand Down

0 comments on commit 46b831c

Please sign in to comment.