1
0
mirror of https://github.com/redis/go-redis.git synced 2025-04-19 07:22:17 +03:00

feat: remove pool unused fields (#2438)

Signed-off-by: monkey92t <golang@88.com>
This commit is contained in:
Monkey 2023-02-12 18:50:25 +08:00 committed by GitHub
parent 2bed94510b
commit 08b4cc5f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,7 +55,6 @@ type Pooler interface {
type Options struct { type Options struct {
Dialer func(context.Context) (net.Conn, error) Dialer func(context.Context) (net.Conn, error)
OnClose func(*Conn) error
PoolFIFO bool PoolFIFO bool
PoolSize int PoolSize int
@ -88,7 +87,6 @@ type ConnPool struct {
stats Stats stats Stats
_closed uint32 // atomic _closed uint32 // atomic
closedCh chan struct{}
} }
var _ Pooler = (*ConnPool)(nil) var _ Pooler = (*ConnPool)(nil)
@ -100,7 +98,6 @@ func NewConnPool(opt *Options) *ConnPool {
queue: make(chan struct{}, opt.PoolSize), queue: make(chan struct{}, opt.PoolSize),
conns: make([]*Conn, 0, opt.PoolSize), conns: make([]*Conn, 0, opt.PoolSize),
idleConns: make([]*Conn, 0, opt.PoolSize), idleConns: make([]*Conn, 0, opt.PoolSize),
closedCh: make(chan struct{}),
} }
p.connsMu.Lock() p.connsMu.Lock()
@ -376,7 +373,7 @@ func (p *ConnPool) Put(ctx context.Context, cn *Conn) {
} }
} }
func (p *ConnPool) Remove(ctx context.Context, cn *Conn, reason error) { func (p *ConnPool) Remove(_ context.Context, cn *Conn, reason error) {
p.removeConnWithLock(cn) p.removeConnWithLock(cn)
p.freeTurn() p.freeTurn()
_ = p.closeConn(cn) _ = p.closeConn(cn)
@ -407,9 +404,6 @@ func (p *ConnPool) removeConn(cn *Conn) {
} }
func (p *ConnPool) closeConn(cn *Conn) error { func (p *ConnPool) closeConn(cn *Conn) error {
if p.cfg.OnClose != nil {
_ = p.cfg.OnClose(cn)
}
return cn.Close() return cn.Close()
} }
@ -464,7 +458,6 @@ func (p *ConnPool) Close() error {
if !atomic.CompareAndSwapUint32(&p._closed, 0, 1) { if !atomic.CompareAndSwapUint32(&p._closed, 0, 1) {
return ErrClosed return ErrClosed
} }
close(p.closedCh)
var firstErr error var firstErr error
p.connsMu.Lock() p.connsMu.Lock()
@ -489,7 +482,6 @@ func (p *ConnPool) isHealthyConn(cn *Conn) bool {
return false return false
} }
if p.cfg.ConnMaxIdleTime > 0 && now.Sub(cn.UsedAt()) >= p.cfg.ConnMaxIdleTime { if p.cfg.ConnMaxIdleTime > 0 && now.Sub(cn.UsedAt()) >= p.cfg.ConnMaxIdleTime {
atomic.AddUint32(&p.stats.IdleConns, 1)
return false return false
} }