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,19 +106,23 @@ func (p *ConnPool) NewConn() (*Conn, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ConnPool) PopFree() *Conn {
|
func (p *ConnPool) PopFree() *Conn {
|
||||||
timer := timers.Get().(*time.Timer)
|
|
||||||
timer.Reset(p.poolTimeout)
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case p.queue <- struct{}{}:
|
case p.queue <- struct{}{}:
|
||||||
if !timer.Stop() {
|
default:
|
||||||
<-timer.C
|
timer := timers.Get().(*time.Timer)
|
||||||
|
timer.Reset(p.poolTimeout)
|
||||||
|
|
||||||
|
select {
|
||||||
|
case p.queue <- struct{}{}:
|
||||||
|
if !timer.Stop() {
|
||||||
|
<-timer.C
|
||||||
|
}
|
||||||
|
timers.Put(timer)
|
||||||
|
case <-timer.C:
|
||||||
|
timers.Put(timer)
|
||||||
|
atomic.AddUint32(&p.stats.Timeouts, 1)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
timers.Put(timer)
|
|
||||||
case <-timer.C:
|
|
||||||
timers.Put(timer)
|
|
||||||
atomic.AddUint32(&p.stats.Timeouts, 1)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.freeConnsMu.Lock()
|
p.freeConnsMu.Lock()
|
||||||
@@ -150,19 +154,23 @@ func (p *ConnPool) Get() (*Conn, bool, error) {
|
|||||||
|
|
||||||
atomic.AddUint32(&p.stats.Requests, 1)
|
atomic.AddUint32(&p.stats.Requests, 1)
|
||||||
|
|
||||||
timer := timers.Get().(*time.Timer)
|
|
||||||
timer.Reset(p.poolTimeout)
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case p.queue <- struct{}{}:
|
case p.queue <- struct{}{}:
|
||||||
if !timer.Stop() {
|
default:
|
||||||
<-timer.C
|
timer := timers.Get().(*time.Timer)
|
||||||
|
timer.Reset(p.poolTimeout)
|
||||||
|
|
||||||
|
select {
|
||||||
|
case p.queue <- struct{}{}:
|
||||||
|
if !timer.Stop() {
|
||||||
|
<-timer.C
|
||||||
|
}
|
||||||
|
timers.Put(timer)
|
||||||
|
case <-timer.C:
|
||||||
|
timers.Put(timer)
|
||||||
|
atomic.AddUint32(&p.stats.Timeouts, 1)
|
||||||
|
return nil, false, ErrPoolTimeout
|
||||||
}
|
}
|
||||||
timers.Put(timer)
|
|
||||||
case <-timer.C:
|
|
||||||
timers.Put(timer)
|
|
||||||
atomic.AddUint32(&p.stats.Timeouts, 1)
|
|
||||||
return nil, false, ErrPoolTimeout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
Reference in New Issue
Block a user