var (
// ErrClosed performs any operation on the closed client will return this error.
ErrClosed = errors.New("redis: client is closed")
// ErrPoolExhausted is returned from a pool connection method
// when the maximum number of database connections in the pool has been reached.
ErrPoolExhausted = errors.New("redis: connection pool exhausted")
// ErrPoolTimeout timed out waiting to get a connection from the connection pool.
ErrPoolTimeout = errors.New("redis: connection pool timeout")
)
type BadConnError struct {
// contains filtered or unexported fields
}
func (e BadConnError) Error() string
func (e BadConnError) Unwrap() error
type Conn struct {
Inited bool
// contains filtered or unexported fields
}
func NewConn(netConn net.Conn) *Conn
func NewConnWithBufferSize(netConn net.Conn, readBufSize, writeBufSize int) *Conn
func (cn *Conn) Close() error
func (cn *Conn) RemoteAddr() net.Addr
func (cn *Conn) SetNetConn(netConn net.Conn)
func (cn *Conn) SetOnClose(fn func() error)
func (cn *Conn) SetUsedAt(tm time.Time)
func (cn *Conn) UsedAt() time.Time
func (cn *Conn) WithReader( ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error, ) error
func (cn *Conn) WithWriter( ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error, ) error
func (cn *Conn) Write(b []byte) (int, error)
type ConnPool struct {
// contains filtered or unexported fields
}
func NewConnPool(opt *Options) *ConnPool
func (p *ConnPool) Close() error
func (p *ConnPool) CloseConn(cn *Conn) error
func (p *ConnPool) Filter(fn func(*Conn) bool) error
func (p *ConnPool) Get(ctx context.Context) (*Conn, error)
Get returns existed connection from the pool or creates a new one.
func (p *ConnPool) IdleLen() int
IdleLen returns number of idle connections.
func (p *ConnPool) Len() int
Len returns total number of connections.
func (p *ConnPool) NewConn(ctx context.Context) (*Conn, error)
func (p *ConnPool) Put(ctx context.Context, cn *Conn)
func (p *ConnPool) Remove(_ context.Context, cn *Conn, reason error)
func (p *ConnPool) Stats() *Stats
type Options struct {
Dialer func(context.Context) (net.Conn, error)
PoolFIFO bool
PoolSize int
DialTimeout time.Duration
PoolTimeout time.Duration
MinIdleConns int
MaxIdleConns int
MaxActiveConns int
ConnMaxIdleTime time.Duration
ConnMaxLifetime time.Duration
ReadBufferSize int
WriteBufferSize int
}
type Pooler interface {
NewConn(context.Context) (*Conn, error)
CloseConn(*Conn) error
Get(context.Context) (*Conn, error)
Put(context.Context, *Conn)
Remove(context.Context, *Conn, error)
Len() int
IdleLen() int
Stats() *Stats
Close() error
}
type SingleConnPool struct {
// contains filtered or unexported fields
}
func NewSingleConnPool(pool Pooler, cn *Conn) *SingleConnPool
func (p *SingleConnPool) Close() error
func (p *SingleConnPool) CloseConn(cn *Conn) error
func (p *SingleConnPool) Get(ctx context.Context) (*Conn, error)
func (p *SingleConnPool) IdleLen() int
func (p *SingleConnPool) Len() int
func (p *SingleConnPool) NewConn(ctx context.Context) (*Conn, error)
func (p *SingleConnPool) Put(ctx context.Context, cn *Conn)
func (p *SingleConnPool) Remove(ctx context.Context, cn *Conn, reason error)
func (p *SingleConnPool) Stats() *Stats
Stats contains pool state information and accumulated stats.
type Stats struct {
Hits uint32 // number of times free connection was found in the pool
Misses uint32 // number of times free connection was NOT found in the pool
Timeouts uint32 // number of times a wait timeout occurred
WaitCount uint32 // number of times a connection was waited
WaitDurationNs int64 // total time spent for waiting a connection in nanoseconds
TotalConns uint32 // number of total connections in the pool
IdleConns uint32 // number of idle connections in the pool
StaleConns uint32 // number of stale connections removed from the pool
}
type StickyConnPool struct {
// contains filtered or unexported fields
}
func NewStickyConnPool(pool Pooler) *StickyConnPool
func (p *StickyConnPool) Close() error
func (p *StickyConnPool) CloseConn(cn *Conn) error
func (p *StickyConnPool) Get(ctx context.Context) (*Conn, error)
func (p *StickyConnPool) IdleLen() int
func (p *StickyConnPool) Len() int
func (p *StickyConnPool) NewConn(ctx context.Context) (*Conn, error)
func (p *StickyConnPool) Put(ctx context.Context, cn *Conn)
func (p *StickyConnPool) Remove(ctx context.Context, cn *Conn, reason error)
func (p *StickyConnPool) Reset(ctx context.Context) error
func (p *StickyConnPool) Stats() *Stats