Skip to content

Commit 0338677

Browse files
committed
fix: prevent sentinel from getting duplicated nodes
1 parent b216e4e commit 0338677

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/connectors/sentinel_connector.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ SentinelConnector.prototype.updateSentinels = function (client, callback) {
9999
var sentinel = utils.packObject(result[i]);
100100
var flags = sentinel.flags ? sentinel.flags.split(',') : [];
101101
if (flags.indexOf('disconnected') === -1 && sentinel.ip && sentinel.port) {
102-
var endpoint = { host: sentinel.ip, port: parseInt(sentinel.port) };
103-
var isDuplicate = _this.sentinels.some(function (o) {
104-
return o.host === endpoint.host && o.port === endpoint.port;
105-
});
102+
var endpoint = { host: sentinel.ip, port: parseInt(sentinel.port, 10) };
103+
var isDuplicate = _this.sentinels.some(_.bind(isSentinelEql, null, endpoint));
106104
if (!isDuplicate) {
107105
debug('adding sentinel %s:%s', endpoint.host, endpoint.port);
108106
_this.sentinels.push(endpoint);
@@ -178,4 +176,9 @@ SentinelConnector.prototype.resolve = function (endpoint, callback) {
178176

179177
function noop() {}
180178

179+
function isSentinelEql(a, b) {
180+
return ((a.host || '127.0.0.1') === (b.host || '127.0.0.1')) &&
181+
((a.port || 6379) === (b.port || 6379));
182+
}
183+
181184
module.exports = SentinelConnector;

0 commit comments

Comments
 (0)