forked from mirror/redis
Fix race
This commit is contained in:
parent
a60ca8bc24
commit
43d9b98d48
|
@ -177,6 +177,7 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
|
||||||
opt.init()
|
opt.init()
|
||||||
|
|
||||||
connPool := newConnPool(opt)
|
connPool := newConnPool(opt)
|
||||||
|
|
||||||
failover.mu.Lock()
|
failover.mu.Lock()
|
||||||
failover.onFailover = func(ctx context.Context, addr string) {
|
failover.onFailover = func(ctx context.Context, addr string) {
|
||||||
_ = connPool.Filter(func(cn *pool.Conn) bool {
|
_ = connPool.Filter(func(cn *pool.Conn) bool {
|
||||||
|
@ -648,6 +649,7 @@ func (c *sentinelFailover) discoverSentinels(ctx context.Context) {
|
||||||
|
|
||||||
func (c *sentinelFailover) listen(pubsub *PubSub) {
|
func (c *sentinelFailover) listen(pubsub *PubSub) {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
|
|
||||||
if c.onUpdate != nil {
|
if c.onUpdate != nil {
|
||||||
c.onUpdate(ctx)
|
c.onUpdate(ctx)
|
||||||
}
|
}
|
||||||
|
@ -725,9 +727,12 @@ func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
c := NewClusterClient(opt)
|
c := NewClusterClient(opt)
|
||||||
|
|
||||||
|
failover.mu.Lock()
|
||||||
failover.onUpdate = func(ctx context.Context) {
|
failover.onUpdate = func(ctx context.Context) {
|
||||||
c.ReloadState(ctx)
|
c.ReloadState(ctx)
|
||||||
}
|
}
|
||||||
|
failover.mu.Unlock()
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue