Skip to content

Commit

Permalink
fix(CLUSTER): fix cluster not disconnected when called disconnect method
Browse files Browse the repository at this point in the history
Related issue: #277
  • Loading branch information
luin committed Apr 9, 2016
1 parent 055429b commit e7b0b11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/cluster/index.js
Expand Up @@ -57,7 +57,7 @@ function Cluster(startupNodes, options) {

var _this = this;
this.connectionPool.on('-node', function (redis) {
if (_this.subscriber === redis) {
if (_this.status === 'ready' && _this.subscriber === redis) {
_this.selectSubscriber();
}
_this.emit('-node', redis);
Expand Down Expand Up @@ -193,6 +193,8 @@ Cluster.prototype.connect = function () {
* @public
*/
Cluster.prototype.disconnect = function (reconnect) {
this.setStatus('disconnecting');

if (!reconnect) {
this.manuallyClosing = true;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/redis.js
Expand Up @@ -300,14 +300,20 @@ Redis.prototype.connect = function (callback) {
* @public
*/
Redis.prototype.disconnect = function (reconnect) {
this.setStatus('disconnecting');

if (!reconnect) {
this.manuallyClosing = true;
}
if (this.reconnectTimeout) {
clearTimeout(this.reconnectTimeout);
this.reconnectTimeout = null;
}
this.connector.disconnect();
if (this.status === 'wait') {
eventHandler.closeHandler(this)();
} else {
this.connector.disconnect();
}
};

/**
Expand Down

0 comments on commit e7b0b11

Please sign in to comment.