forked from mirror/redis
Merge pull request #586 from go-redis/fix/pool-fast-path
pool: add fast path
This commit is contained in:
commit
c8159532bc
|
@ -106,6 +106,9 @@ func (p *ConnPool) NewConn() (*Conn, error) {
|
|||
}
|
||||
|
||||
func (p *ConnPool) PopFree() *Conn {
|
||||
select {
|
||||
case p.queue <- struct{}{}:
|
||||
default:
|
||||
timer := timers.Get().(*time.Timer)
|
||||
timer.Reset(p.poolTimeout)
|
||||
|
||||
|
@ -120,6 +123,7 @@ func (p *ConnPool) PopFree() *Conn {
|
|||
atomic.AddUint32(&p.stats.Timeouts, 1)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
p.freeConnsMu.Lock()
|
||||
cn := p.popFree()
|
||||
|
@ -150,6 +154,9 @@ func (p *ConnPool) Get() (*Conn, bool, error) {
|
|||
|
||||
atomic.AddUint32(&p.stats.Requests, 1)
|
||||
|
||||
select {
|
||||
case p.queue <- struct{}{}:
|
||||
default:
|
||||
timer := timers.Get().(*time.Timer)
|
||||
timer.Reset(p.poolTimeout)
|
||||
|
||||
|
@ -164,6 +171,7 @@ func (p *ConnPool) Get() (*Conn, bool, error) {
|
|||
atomic.AddUint32(&p.stats.Timeouts, 1)
|
||||
return nil, false, ErrPoolTimeout
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
p.freeConnsMu.Lock()
|
||||
|
|
Loading…
Reference in New Issue