1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-11 22:42:42 +03:00

better cluster nodes discorvery strategy after MOVED error, add PubSub test

This commit is contained in:
leibale
2021-06-11 17:29:20 -04:00
parent 71242304bc
commit c29c1bb7d2
7 changed files with 312 additions and 9 deletions

View File

@@ -204,9 +204,15 @@ export default class RedisCommandsQueue {
return this.#pushPubSubCommand(command, channelsToSubscribe);
}
unsubscribe(command: PubSubUnsubscribeCommands, channels: string | Array<string>, listener?: PubSubListener) {
const listeners = command === PubSubUnsubscribeCommands.UNSUBSCRIBE ? this.#pubSubListeners.channels : this.#pubSubListeners.patterns,
channelsToUnsubscribe = [];
unsubscribe(command: PubSubUnsubscribeCommands, channels?: string | Array<string>, listener?: PubSubListener) {
const listeners = command === PubSubUnsubscribeCommands.UNSUBSCRIBE ? this.#pubSubListeners.channels : this.#pubSubListeners.patterns;
if (!channels) {
const keys = [...listeners.keys()];
listeners.clear();
return this.#pushPubSubCommand(command, keys);
}
const channelsToUnsubscribe = [];
for (const channel of (Array.isArray(channels) ? channels : [channels])) {
const set = listeners.get(channel);
if (!set) continue;