redis/internal/pool/pool_single.go

59 lines
1.0 KiB
Go
Raw Permalink Normal View History

package pool
2020-08-15 15:36:02 +03:00
import "context"
type SingleConnPool struct {
2020-08-15 15:36:02 +03:00
pool Pooler
cn *Conn
stickyErr error
}
var _ Pooler = (*SingleConnPool)(nil)
2020-08-15 15:36:02 +03:00
func NewSingleConnPool(pool Pooler, cn *Conn) *SingleConnPool {
return &SingleConnPool{
pool: pool,
cn: cn,
}
}
2019-08-18 17:03:32 +03:00
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)
}
2019-08-18 17:03:32 +03:00
func (p *SingleConnPool) Get(ctx context.Context) (*Conn, error) {
2020-08-15 15:36:02 +03:00
if p.stickyErr != nil {
return nil, p.stickyErr
2019-08-02 00:59:53 +03:00
}
2020-08-15 15:36:02 +03:00
return p.cn, nil
}
2020-08-15 15:36:02 +03:00
func (p *SingleConnPool) Put(ctx context.Context, cn *Conn) {}
2020-08-15 15:36:02 +03:00
func (p *SingleConnPool) Remove(ctx context.Context, cn *Conn, reason error) {
p.cn = nil
p.stickyErr = reason
}
2020-08-15 15:36:02 +03:00
func (p *SingleConnPool) Close() error {
p.cn = nil
p.stickyErr = ErrClosed
return nil
}
func (p *SingleConnPool) Len() int {
2020-08-15 15:36:02 +03:00
return 0
}
2018-05-28 17:27:24 +03:00
func (p *SingleConnPool) IdleLen() int {
2020-08-15 15:36:02 +03:00
return 0
}
func (p *SingleConnPool) Stats() *Stats {
return &Stats{}
}