Skip to content

Commit f63e0d6

Browse files
authored
Merge pull request #1693 from monkey92t/sentinel
discoverSentinels read the addr field incorrectly
2 parents 573638f + c25daee commit f63e0d6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

sentinel.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,22 @@ func (c *sentinelFailover) discoverSentinels(ctx context.Context) {
666666
}
667667
for _, sentinel := range sentinels {
668668
vals := sentinel.([]interface{})
669+
var ip, port string
669670
for i := 0; i < len(vals); i += 2 {
670671
key := vals[i].(string)
671-
if key == "name" {
672-
sentinelAddr := vals[i+1].(string)
673-
if !contains(c.sentinelAddrs, sentinelAddr) {
674-
internal.Logger.Printf(ctx, "sentinel: discovered new sentinel=%q for master=%q",
675-
sentinelAddr, c.opt.MasterName)
676-
c.sentinelAddrs = append(c.sentinelAddrs, sentinelAddr)
677-
}
672+
switch key {
673+
case "ip":
674+
ip = vals[i+1].(string)
675+
case "port":
676+
port = vals[i+1].(string)
677+
}
678+
}
679+
if ip != "" && port != "" {
680+
sentinelAddr := net.JoinHostPort(ip, port)
681+
if !contains(c.sentinelAddrs, sentinelAddr) {
682+
internal.Logger.Printf(ctx, "sentinel: discovered new sentinel=%q for master=%q",
683+
sentinelAddr, c.opt.MasterName)
684+
c.sentinelAddrs = append(c.sentinelAddrs, sentinelAddr)
678685
}
679686
}
680687
}

0 commit comments

Comments
 (0)