mirror of https://github.com/go-redis/redis.git
Shuffle sentinel addrs once
This commit is contained in:
parent
8b19c31049
commit
8d9ebc8459
14
sentinel.go
14
sentinel.go
|
@ -173,6 +173,10 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
|
|||
sentinelAddrs := make([]string, len(failoverOpt.SentinelAddrs))
|
||||
copy(sentinelAddrs, failoverOpt.SentinelAddrs)
|
||||
|
||||
rand.Shuffle(len(sentinelAddrs), func(i, j int) {
|
||||
sentinelAddrs[i], sentinelAddrs[j] = sentinelAddrs[j], sentinelAddrs[i]
|
||||
})
|
||||
|
||||
failover := &sentinelFailover{
|
||||
opt: failoverOpt,
|
||||
sentinelAddrs: sentinelAddrs,
|
||||
|
@ -484,11 +488,6 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) {
|
|||
_ = c.closeSentinel()
|
||||
}
|
||||
|
||||
if c.opt.QuerySentinelRandomly {
|
||||
rand.Shuffle(len(c.sentinelAddrs), func(i, j int) {
|
||||
c.sentinelAddrs[i], c.sentinelAddrs[j] = c.sentinelAddrs[j], c.sentinelAddrs[i]
|
||||
})
|
||||
}
|
||||
for i, sentinelAddr := range c.sentinelAddrs {
|
||||
sentinel := NewSentinelClient(c.opt.sentinelOptions(sentinelAddr))
|
||||
|
||||
|
@ -533,11 +532,6 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, useDisconnected bool)
|
|||
}
|
||||
_ = c.closeSentinel()
|
||||
}
|
||||
if c.opt.QuerySentinelRandomly {
|
||||
rand.Shuffle(len(c.sentinelAddrs), func(i, j int) {
|
||||
c.sentinelAddrs[i], c.sentinelAddrs[j] = c.sentinelAddrs[j], c.sentinelAddrs[i]
|
||||
})
|
||||
}
|
||||
|
||||
var sentinelReachable bool
|
||||
|
||||
|
|
Loading…
Reference in New Issue