mirror of
https://github.com/redis/go-redis.git
synced 2025-08-06 01:35:48 +03:00
pool: add fast path
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user