forked from mirror/redis
Cleanup
This commit is contained in:
parent
e471faf7f8
commit
e694ed0084
|
@ -49,7 +49,7 @@ type Pooler interface {
|
|||
}
|
||||
|
||||
type Options struct {
|
||||
Dialer func(c context.Context) (net.Conn, error)
|
||||
Dialer func(context.Context) (net.Conn, error)
|
||||
OnClose func(*Conn) error
|
||||
|
||||
PoolSize int
|
||||
|
|
|
@ -58,20 +58,20 @@ func (p *SingleConnPool) SetConn(cn *Conn) {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *SingleConnPool) NewConn(c context.Context) (*Conn, error) {
|
||||
return p.pool.NewConn(c)
|
||||
func (p *SingleConnPool) NewConn(ctx context.Context) (*Conn, error) {
|
||||
return p.pool.NewConn(ctx)
|
||||
}
|
||||
|
||||
func (p *SingleConnPool) CloseConn(cn *Conn) error {
|
||||
return p.pool.CloseConn(cn)
|
||||
}
|
||||
|
||||
func (p *SingleConnPool) Get(c context.Context) (*Conn, error) {
|
||||
func (p *SingleConnPool) Get(ctx context.Context) (*Conn, error) {
|
||||
// In worst case this races with Close which is not a very common operation.
|
||||
for i := 0; i < 1000; i++ {
|
||||
switch atomic.LoadUint32(&p.state) {
|
||||
case stateDefault:
|
||||
cn, err := p.pool.Get(c)
|
||||
cn, err := p.pool.Get(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -215,8 +215,8 @@ func ParseURL(redisURL string) (*Options, error) {
|
|||
|
||||
func newConnPool(opt *Options) *pool.ConnPool {
|
||||
return pool.NewConnPool(&pool.Options{
|
||||
Dialer: func(c context.Context) (net.Conn, error) {
|
||||
return opt.Dialer(c, opt.Network, opt.Addr)
|
||||
Dialer: func(ctx context.Context) (net.Conn, error) {
|
||||
return opt.Dialer(ctx, opt.Network, opt.Addr)
|
||||
},
|
||||
PoolSize: opt.PoolSize,
|
||||
MinIdleConns: opt.MinIdleConns,
|
||||
|
|
Loading…
Reference in New Issue