From c25daee5e611628c9ae5bb6d4b4945ab6456b244 Mon Sep 17 00:00:00 2001 From: monkey Date: Fri, 12 Mar 2021 23:20:58 +0800 Subject: [PATCH] discoverSentinels read the addr field incorrectly Signed-off-by: monkey --- sentinel.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/sentinel.go b/sentinel.go index 3e8afb7..85b459b 100644 --- a/sentinel.go +++ b/sentinel.go @@ -666,15 +666,22 @@ func (c *sentinelFailover) discoverSentinels(ctx context.Context) { } for _, sentinel := range sentinels { vals := sentinel.([]interface{}) + var ip, port string for i := 0; i < len(vals); i += 2 { key := vals[i].(string) - if key == "name" { - sentinelAddr := vals[i+1].(string) - if !contains(c.sentinelAddrs, sentinelAddr) { - internal.Logger.Printf(ctx, "sentinel: discovered new sentinel=%q for master=%q", - sentinelAddr, c.opt.MasterName) - c.sentinelAddrs = append(c.sentinelAddrs, sentinelAddr) - } + switch key { + case "ip": + ip = vals[i+1].(string) + case "port": + port = vals[i+1].(string) + } + } + if ip != "" && port != "" { + sentinelAddr := net.JoinHostPort(ip, port) + if !contains(c.sentinelAddrs, sentinelAddr) { + internal.Logger.Printf(ctx, "sentinel: discovered new sentinel=%q for master=%q", + sentinelAddr, c.opt.MasterName) + c.sentinelAddrs = append(c.sentinelAddrs, sentinelAddr) } } }