You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
fix #1652
This commit is contained in:
@@ -516,6 +516,9 @@ describe('Client', () => {
|
|||||||
assert.ok(channelListener1.calledOnce);
|
assert.ok(channelListener1.calledOnce);
|
||||||
assert.ok(channelListener2.calledTwice);
|
assert.ok(channelListener2.calledTwice);
|
||||||
assert.ok(patternListener.calledThrice);
|
assert.ok(patternListener.calledThrice);
|
||||||
|
|
||||||
|
// should be able to send commands when unsubsribed from all channels (see #1652)
|
||||||
|
await assert.doesNotReject(subscriber.ping());
|
||||||
} finally {
|
} finally {
|
||||||
await subscriber.disconnect();
|
await subscriber.disconnect();
|
||||||
}
|
}
|
||||||
|
@@ -171,8 +171,9 @@ export default class RedisCommandsQueue {
|
|||||||
unsubscribe(command: PubSubUnsubscribeCommands, channels?: string | Array<string>, listener?: PubSubListener): Promise<void> {
|
unsubscribe(command: PubSubUnsubscribeCommands, channels?: string | Array<string>, listener?: PubSubListener): Promise<void> {
|
||||||
const listeners = command === PubSubUnsubscribeCommands.UNSUBSCRIBE ? this.#pubSubListeners.channels : this.#pubSubListeners.patterns;
|
const listeners = command === PubSubUnsubscribeCommands.UNSUBSCRIBE ? this.#pubSubListeners.channels : this.#pubSubListeners.patterns;
|
||||||
if (!channels) {
|
if (!channels) {
|
||||||
|
const size = listeners.size;
|
||||||
listeners.clear();
|
listeners.clear();
|
||||||
return this.#pushPubSubCommand(command);
|
return this.#pushPubSubCommand(command, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
const channelsToUnsubscribe = [];
|
const channelsToUnsubscribe = [];
|
||||||
@@ -199,22 +200,18 @@ export default class RedisCommandsQueue {
|
|||||||
return this.#pushPubSubCommand(command, channelsToUnsubscribe);
|
return this.#pushPubSubCommand(command, channelsToUnsubscribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pushPubSubCommand(command: PubSubSubscribeCommands | PubSubUnsubscribeCommands, channels?: Array<string>): Promise<void> {
|
#pushPubSubCommand(command: PubSubSubscribeCommands | PubSubUnsubscribeCommands, channels: number | Array<string>): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const isSubscribe = command === PubSubSubscribeCommands.SUBSCRIBE || command === PubSubSubscribeCommands.PSUBSCRIBE,
|
const isSubscribe = command === PubSubSubscribeCommands.SUBSCRIBE || command === PubSubSubscribeCommands.PSUBSCRIBE,
|
||||||
inProgressKey = isSubscribe ? 'subscribing' : 'unsubscribing',
|
inProgressKey = isSubscribe ? 'subscribing' : 'unsubscribing',
|
||||||
commandArgs: Array<string> = [command];
|
commandArgs: Array<string> = [command];
|
||||||
|
|
||||||
let channelsCounter: number;
|
let channelsCounter: number;
|
||||||
if (channels?.length) {
|
if (typeof channels === 'number') { // unsubscribe only
|
||||||
|
channelsCounter = channels;
|
||||||
|
} else {
|
||||||
commandArgs.push(...channels);
|
commandArgs.push(...channels);
|
||||||
channelsCounter = channels.length;
|
channelsCounter = channels.length;
|
||||||
} else {
|
|
||||||
// unsubscribe only
|
|
||||||
channelsCounter = (
|
|
||||||
command[0] === 'P' ?
|
|
||||||
this.#pubSubListeners.patterns :
|
|
||||||
this.#pubSubListeners.channels
|
|
||||||
).size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#pubSubState[inProgressKey] += channelsCounter;
|
this.#pubSubState[inProgressKey] += channelsCounter;
|
||||||
|
Reference in New Issue
Block a user