diff --git a/lib/connectors/sentinel_connector.js b/lib/connectors/sentinel_connector.js index ff486b4d..98d32488 100644 --- a/lib/connectors/sentinel_connector.js +++ b/lib/connectors/sentinel_connector.js @@ -28,7 +28,7 @@ SentinelConnector.prototype.check = function (info) { return true; }; -SentinelConnector.prototype.connect = function (callback) { +SentinelConnector.prototype.connect = function (callback, eventEmitter) { this.connecting = true; this.retryAttempts = 0; @@ -48,20 +48,24 @@ SentinelConnector.prototype.connect = function (callback) { if (_this.currentPoint === _this.sentinels.length) { _this.currentPoint = -1; + var error; var retryDelay; if (typeof _this.options.sentinelRetryStrategy === 'function') { retryDelay = _this.options.sentinelRetryStrategy(++_this.retryAttempts); } + if (typeof retryDelay !== 'number') { debug('All sentinels are unreachable and retry is disabled, emitting error...'); - var error = 'All sentinels are unreachable.'; + error = 'All sentinels are unreachable.'; if (lastError) { error += ' Last error: ' + lastError.message; } return callback(new Error(error)); } debug('All sentinels are unreachable. Retrying from scratch after %d', retryDelay); + error = 'All sentinels are unreachable, retrying...'; setTimeout(connectToNext, retryDelay); + eventEmitter('error', new Error(error)); return; } @@ -76,11 +80,13 @@ SentinelConnector.prototype.connect = function (callback) { callback(null, _this.stream); } else if (err) { debug('failed to connect to sentinel %s:%s because %s', endpoint.host, endpoint.port, err); + eventEmitter('sentinelError', new Error('failed to connect to sentinel '+endpoint.host+':'+endpoint.port+' because '+err)); lastError = err; connectToNext(); } else { debug('connected to sentinel %s:%s successfully, but got a invalid reply: %s', endpoint.host, endpoint.port, resolved); + eventEmitter('sentinelError', new Error('connected to sentinel '+endpoint.host+':'+endpoint.port+' successfully, but got a invalid reply: '+resolved)); connectToNext(); } }); diff --git a/lib/redis.js b/lib/redis.js index e0dcdef7..30ed7a1e 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -311,6 +311,8 @@ Redis.prototype.connect = function (callback) { }; _this.once(CONNECT_EVENT, connectionConnectHandler); _this.once('close', connectionCloseHandler); + }, function(type, err) { + _this.silentEmit(type, err); }); }.bind(this)).nodeify(callback); };