Skip to content

Commit

Permalink
fix: prevent sentinel from getting duplicated nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Sep 24, 2016
1 parent b216e4e commit 0338677
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/connectors/sentinel_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ SentinelConnector.prototype.updateSentinels = function (client, callback) {
var sentinel = utils.packObject(result[i]);
var flags = sentinel.flags ? sentinel.flags.split(',') : [];
if (flags.indexOf('disconnected') === -1 && sentinel.ip && sentinel.port) {
var endpoint = { host: sentinel.ip, port: parseInt(sentinel.port) };
var isDuplicate = _this.sentinels.some(function (o) {
return o.host === endpoint.host && o.port === endpoint.port;
});
var endpoint = { host: sentinel.ip, port: parseInt(sentinel.port, 10) };
var isDuplicate = _this.sentinels.some(_.bind(isSentinelEql, null, endpoint));
if (!isDuplicate) {
debug('adding sentinel %s:%s', endpoint.host, endpoint.port);
_this.sentinels.push(endpoint);
Expand Down Expand Up @@ -178,4 +176,9 @@ SentinelConnector.prototype.resolve = function (endpoint, callback) {

function noop() {}

function isSentinelEql(a, b) {
return ((a.host || '127.0.0.1') === (b.host || '127.0.0.1')) &&
((a.port || 6379) === (b.port || 6379));
}

module.exports = SentinelConnector;

0 comments on commit 0338677

Please sign in to comment.