MCPcopy
hub / github.com/redis/go-redis / discoverSentinels

Method discoverSentinels

sentinel.go:1143–1167  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

1141}
1142
1143func (c *sentinelFailover) discoverSentinels(ctx context.Context) {
1144 sentinels, err := c.sentinel.Sentinels(ctx, c.opt.MasterName).Result()
1145 if err != nil {
1146 internal.Logger.Printf(ctx, "sentinel: Sentinels master=%q failed: %s", c.opt.MasterName, err)
1147 return
1148 }
1149 for _, sentinel := range sentinels {
1150 ip, ok := sentinel["ip"]
1151 if !ok {
1152 continue
1153 }
1154 port, ok := sentinel["port"]
1155 if !ok {
1156 continue
1157 }
1158 if ip != "" && port != "" {
1159 sentinelAddr := net.JoinHostPort(ip, port)
1160 if !slices.Contains(c.sentinelAddrs, sentinelAddr) {
1161 internal.Logger.Printf(ctx, "sentinel: discovered new sentinel=%q for master=%q",
1162 sentinelAddr, c.opt.MasterName)
1163 c.sentinelAddrs = append(c.sentinelAddrs, sentinelAddr)
1164 }
1165 }
1166 }
1167}
1168
1169func (c *sentinelFailover) listen(pubsub *PubSub) {
1170 ctx := context.TODO()

Callers 1

setSentinelMethod · 0.95

Calls 4

SentinelsMethod · 0.80
ResultMethod · 0.65
PrintfMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected