pool

package
v0.0.0-...-302c6ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2021 License: BSD-2-Clause Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed performs any operation on the closed client will return this error.
	ErrClosed = errors.New("redis: client is closed")

	// ErrPoolTimeout timed out waiting to get a connection from the connection pool.
	ErrPoolTimeout = errors.New("redis: connection pool timeout")
)

Functions

func NewConn

func NewConn(c Conn) *conn

Types

type Conn

type Conn interface {
	Close() error
}

type ConnPool

type ConnPool struct {
	// contains filtered or unexported fields
}

func NewConnPool

func NewConnPool(opt *Options) *ConnPool

func (*ConnPool) Close

func (p *ConnPool) Close() error

func (*ConnPool) CloseConn

func (p *ConnPool) CloseConn(cn *conn) error

func (*ConnPool) Filter

func (p *ConnPool) Filter(fn func(*conn) bool) error

func (*ConnPool) Get

func (p *ConnPool) Get(ctx context.Context) (*conn, error)

Get returns existed connection from the pool or creates a new one.

func (*ConnPool) IdleLen

func (p *ConnPool) IdleLen() int

IdleLen returns number of idle connections.

func (*ConnPool) Len

func (p *ConnPool) Len() int

Len returns total number of connections.

func (*ConnPool) NewConn

func (p *ConnPool) NewConn(ctx context.Context) (*conn, error)

func (*ConnPool) Put

func (p *ConnPool) Put(ctx context.Context, cn *conn)

func (*ConnPool) ReapStaleConns

func (p *ConnPool) ReapStaleConns() (int, error)

func (*ConnPool) Remove

func (p *ConnPool) Remove(ctx context.Context, cn *conn, reason error)

func (*ConnPool) WithConn

func (p *ConnPool) WithConn(ctx context.Context, fn func(context.Context, Conn) error) error

type Options

type Options struct {
	// The network type, either tcp or unix.
	// Default is tcp.
	Network string
	// host:port address.
	Addr string

	// Dialer creates new network connection and has priority over
	// Network and Addr options.
	Dialer func(context.Context) (Conn, error)

	OnClose func(Conn) error

	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout time.Duration
	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
	// Default is 3 seconds.
	ReadTimeout time.Duration
	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is ReadTimeout.
	WriteTimeout time.Duration

	PoolSize           int
	MinIdleConns       int
	MaxConnAge         time.Duration
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration

	// TLS Config to use. When set TLS will be negotiated.
	TLSConfig *tls.Config

	Logger *log.Logger
}

type Pooler

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

	Close() error
}

type 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

	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
}

Stats contains pool state information and accumulated stats.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL