forked from mirror/redis
commit
ba0b485159
|
@ -11,7 +11,7 @@ type StickyConnPool struct {
|
|||
|
||||
cn *Conn
|
||||
closed bool
|
||||
mx sync.Mutex
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
var _ Pooler = (*StickyConnPool)(nil)
|
||||
|
@ -24,15 +24,15 @@ func NewStickyConnPool(pool *ConnPool, reusable bool) *StickyConnPool {
|
|||
}
|
||||
|
||||
func (p *StickyConnPool) First() *Conn {
|
||||
p.mx.Lock()
|
||||
p.mu.Lock()
|
||||
cn := p.cn
|
||||
p.mx.Unlock()
|
||||
p.mu.Unlock()
|
||||
return cn
|
||||
}
|
||||
|
||||
func (p *StickyConnPool) Get() (*Conn, bool, error) {
|
||||
defer p.mx.Unlock()
|
||||
p.mx.Lock()
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.closed {
|
||||
return nil, false, ErrClosed
|
||||
|
@ -56,8 +56,9 @@ func (p *StickyConnPool) putUpstream() (err error) {
|
|||
}
|
||||
|
||||
func (p *StickyConnPool) Put(cn *Conn) error {
|
||||
defer p.mx.Unlock()
|
||||
p.mx.Lock()
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.closed {
|
||||
return ErrClosed
|
||||
}
|
||||
|
@ -74,8 +75,9 @@ func (p *StickyConnPool) removeUpstream(reason error) error {
|
|||
}
|
||||
|
||||
func (p *StickyConnPool) Remove(cn *Conn, reason error) error {
|
||||
defer p.mx.Unlock()
|
||||
p.mx.Lock()
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.closed {
|
||||
return nil
|
||||
}
|
||||
|
@ -89,8 +91,9 @@ func (p *StickyConnPool) Remove(cn *Conn, reason error) error {
|
|||
}
|
||||
|
||||
func (p *StickyConnPool) Len() int {
|
||||
defer p.mx.Unlock()
|
||||
p.mx.Lock()
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.cn == nil {
|
||||
return 0
|
||||
}
|
||||
|
@ -98,8 +101,9 @@ func (p *StickyConnPool) Len() int {
|
|||
}
|
||||
|
||||
func (p *StickyConnPool) FreeLen() int {
|
||||
defer p.mx.Unlock()
|
||||
p.mx.Lock()
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.cn == nil {
|
||||
return 1
|
||||
}
|
||||
|
@ -111,8 +115,9 @@ func (p *StickyConnPool) Stats() *Stats {
|
|||
}
|
||||
|
||||
func (p *StickyConnPool) Close() error {
|
||||
defer p.mx.Unlock()
|
||||
p.mx.Lock()
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.closed {
|
||||
return ErrClosed
|
||||
}
|
||||
|
@ -130,8 +135,8 @@ func (p *StickyConnPool) Close() error {
|
|||
}
|
||||
|
||||
func (p *StickyConnPool) Closed() bool {
|
||||
p.mx.Lock()
|
||||
p.mu.Lock()
|
||||
closed := p.closed
|
||||
p.mx.Unlock()
|
||||
p.mu.Unlock()
|
||||
return closed
|
||||
}
|
||||
|
|
|
@ -61,8 +61,8 @@ func (c *Pipeline) discard() error {
|
|||
// Exec always returns list of commands and error of the first failed
|
||||
// command if any.
|
||||
func (c *Pipeline) Exec() ([]Cmder, error) {
|
||||
defer c.mu.Unlock()
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
if c.closed {
|
||||
return nil, pool.ErrClosed
|
||||
|
|
2
ring.go
2
ring.go
|
@ -328,8 +328,8 @@ func (c *Ring) heartbeat() {
|
|||
// It is rare to Close a Ring, as the Ring is meant to be long-lived
|
||||
// and shared between many goroutines.
|
||||
func (c *Ring) Close() error {
|
||||
defer c.mu.Unlock()
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
if c.closed {
|
||||
return nil
|
||||
|
|
|
@ -162,8 +162,8 @@ func (d *sentinelFailover) Pool() *pool.ConnPool {
|
|||
}
|
||||
|
||||
func (d *sentinelFailover) MasterAddr() (string, error) {
|
||||
defer d.mu.Unlock()
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
// Try last working sentinel.
|
||||
if d.sentinel != nil {
|
||||
|
|
Loading…
Reference in New Issue