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