mirror of
https://github.com/redis/go-redis.git
synced 2025-12-02 06:22:31 +03:00
fix linter issues
This commit is contained in:
@@ -20,5 +20,5 @@ func (p *ConnPool) CheckMinIdleConns() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ConnPool) QueueLen() int {
|
func (p *ConnPool) QueueLen() int {
|
||||||
return int(p.semaphore.len())
|
return int(p.semaphore.count.Load())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -486,19 +486,20 @@ func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process connection using the hooks system
|
// Process connection using the hooks system
|
||||||
|
// Combine error and rejection checks to reduce branches
|
||||||
if hookManager != nil {
|
if hookManager != nil {
|
||||||
acceptConn, err := hookManager.ProcessOnGet(ctx, cn, false)
|
acceptConn, err := hookManager.ProcessOnGet(ctx, cn, false)
|
||||||
if err != nil {
|
if err != nil || !acceptConn {
|
||||||
internal.Logger.Printf(ctx, "redis: connection pool: failed to process idle connection by hook: %v", err)
|
if err != nil {
|
||||||
_ = p.CloseConn(cn)
|
internal.Logger.Printf(ctx, "redis: connection pool: failed to process idle connection by hook: %v", err)
|
||||||
continue
|
_ = p.CloseConn(cn)
|
||||||
}
|
} else {
|
||||||
if !acceptConn {
|
internal.Logger.Printf(ctx, "redis: connection pool: conn[%d] rejected by hook, returning to pool", cn.GetID())
|
||||||
internal.Logger.Printf(ctx, "redis: connection pool: conn[%d] rejected by hook, returning to pool", cn.GetID())
|
// Return connection to pool without freeing the turn that this Get() call holds.
|
||||||
// Return connection to pool without freeing the turn that this Get() call holds.
|
// We use putConnWithoutTurn() to run all the Put hooks and logic without freeing a turn.
|
||||||
// We use putConnWithoutTurn() to run all the Put hooks and logic without freeing a turn.
|
p.putConnWithoutTurn(ctx, cn)
|
||||||
p.putConnWithoutTurn(ctx, cn)
|
cn = nil
|
||||||
cn = nil
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,11 +548,12 @@ func (p *ConnPool) waitTurn(ctx context.Context) error {
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
err := p.semaphore.acquire(ctx, p.cfg.PoolTimeout)
|
err := p.semaphore.acquire(ctx, p.cfg.PoolTimeout)
|
||||||
|
|
||||||
if err == nil {
|
switch err {
|
||||||
|
case nil:
|
||||||
// Successfully acquired after waiting
|
// Successfully acquired after waiting
|
||||||
p.waitDurationNs.Add(time.Now().UnixNano() - start.UnixNano())
|
p.waitDurationNs.Add(time.Now().UnixNano() - start.UnixNano())
|
||||||
atomic.AddUint32(&p.stats.WaitCount, 1)
|
atomic.AddUint32(&p.stats.WaitCount, 1)
|
||||||
} else if err == ErrPoolTimeout {
|
case ErrPoolTimeout:
|
||||||
atomic.AddUint32(&p.stats.Timeouts, 1)
|
atomic.AddUint32(&p.stats.Timeouts, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,18 +667,12 @@ func (p *ConnPool) putConn(ctx context.Context, cn *Conn, freeTurn bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If hooks say to remove the connection, do so
|
// Combine all removal checks into one - reduces branches
|
||||||
if shouldRemove {
|
if shouldRemove || !shouldPool {
|
||||||
p.removeConnInternal(ctx, cn, errors.New("hook requested removal"), freeTurn)
|
p.removeConnInternal(ctx, cn, errors.New("hook requested removal"), freeTurn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If processor says not to pool the connection, remove it
|
|
||||||
if !shouldPool {
|
|
||||||
p.removeConnInternal(ctx, cn, errors.New("hook requested no pooling"), freeTurn)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cn.pooled {
|
if !cn.pooled {
|
||||||
p.removeConnInternal(ctx, cn, errors.New("connection not pooled"), freeTurn)
|
p.removeConnInternal(ctx, cn, errors.New("connection not pooled"), freeTurn)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -124,15 +124,4 @@ func (s *fastSemaphore) release() {
|
|||||||
default:
|
default:
|
||||||
// No waiters, that's fine
|
// No waiters, that's fine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// len returns the current number of acquired tokens.
|
|
||||||
func (s *fastSemaphore) len() int32 {
|
|
||||||
return s.count.Load()
|
|
||||||
}
|
|
||||||
|
|
||||||
// cap returns the maximum capacity of the semaphore.
|
|
||||||
func (s *fastSemaphore) cap() int32 {
|
|
||||||
return s.max
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user