diff --git a/lib/cluster/index.js b/lib/cluster/index.js index 926da182..959dc11c 100644 --- a/lib/cluster/index.js +++ b/lib/cluster/index.js @@ -337,7 +337,7 @@ Cluster.prototype.refreshSlotsCache = function (callback) { }; /** - * Flush offline queue and command queue with error. + * Flush offline queue with error. * * @param {Error} error - The error object to send to the commands * @private diff --git a/lib/redis.js b/lib/redis.js index 73626dd5..c1f62b2a 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -315,9 +315,6 @@ Redis.prototype.disconnect = function (reconnect) { if (this.status === 'wait') { eventHandler.closeHandler(this)(); } else { - if (this.stream) { - this.stream.removeAllListeners('data'); - } this.connector.disconnect(); } }; @@ -359,9 +356,14 @@ Redis.prototype.flushQueue = function (error) { item.command.reject(error); } - while (this.commandQueue.length > 0) { - item = this.commandQueue.shift(); - item.command.reject(error); + if (this.commandQueue.length > 0) { + if (this.stream) { + this.stream.removeAllListeners('data'); + } + while (this.commandQueue.length > 0) { + item = this.commandQueue.shift(); + item.command.reject(error); + } } };