forked from mirror/redis
parent
17c058513b
commit
7f69d5e320
18
sentinel.go
18
sentinel.go
|
@ -245,7 +245,9 @@ func (c *sentinelFailover) MasterAddr() (string, error) {
|
|||
}
|
||||
|
||||
func (c *sentinelFailover) masterAddr() (string, error) {
|
||||
c.mu.RLock()
|
||||
addr := c.getMasterAddr()
|
||||
c.mu.RUnlock()
|
||||
if addr != "" {
|
||||
return addr, nil
|
||||
}
|
||||
|
@ -253,6 +255,15 @@ func (c *sentinelFailover) masterAddr() (string, error) {
|
|||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
addr = c.getMasterAddr()
|
||||
if addr != "" {
|
||||
return addr, nil
|
||||
}
|
||||
|
||||
if c.sentinel != nil {
|
||||
c.closeSentinel()
|
||||
}
|
||||
|
||||
for i, sentinelAddr := range c.sentinelAddrs {
|
||||
sentinel := NewSentinelClient(&Options{
|
||||
Addr: sentinelAddr,
|
||||
|
@ -291,9 +302,7 @@ func (c *sentinelFailover) masterAddr() (string, error) {
|
|||
}
|
||||
|
||||
func (c *sentinelFailover) getMasterAddr() string {
|
||||
c.mu.RLock()
|
||||
sentinel := c.sentinel
|
||||
c.mu.RUnlock()
|
||||
|
||||
if sentinel == nil {
|
||||
return ""
|
||||
|
@ -303,11 +312,6 @@ func (c *sentinelFailover) getMasterAddr() string {
|
|||
if err != nil {
|
||||
internal.Logf("sentinel: GetMasterAddrByName name=%q failed: %s",
|
||||
c.masterName, err)
|
||||
c.mu.Lock()
|
||||
if c.sentinel == sentinel {
|
||||
c.closeSentinel()
|
||||
}
|
||||
c.mu.Unlock()
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue