...

Package pool

import "github.com/redis/go-redis/v9/internal/pool"
Overview
Index

Overview ▾

Index ▾

Variables
type BadConnError
    func (e BadConnError) Error() string
    func (e BadConnError) Unwrap() error
type Conn
    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
    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)
    func (p *ConnPool) IdleLen() int
    func (p *ConnPool) Len() int
    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
type Pooler
type SingleConnPool
    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
type Stats
type StickyConnPool
    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

Package files

conn.go conn_check.go pool.go pool_single.go pool_sticky.go

Variables

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

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

func (BadConnError) Error

func (e BadConnError) Error() string

func (BadConnError) Unwrap

func (e BadConnError) Unwrap() error

type Conn

type Conn struct {
    Inited bool
    // contains filtered or unexported fields
}

func NewConn

func NewConn(netConn net.Conn) *Conn

func NewConnWithBufferSize

func NewConnWithBufferSize(netConn net.Conn, readBufSize, writeBufSize int) *Conn

func (*Conn) Close

func (cn *Conn) Close() error

func (*Conn) RemoteAddr

func (cn *Conn) RemoteAddr() net.Addr

func (*Conn) SetNetConn

func (cn *Conn) SetNetConn(netConn net.Conn)

func (*Conn) SetOnClose

func (cn *Conn) SetOnClose(fn func() error)

func (*Conn) SetUsedAt

func (cn *Conn) SetUsedAt(tm time.Time)

func (*Conn) UsedAt

func (cn *Conn) UsedAt() time.Time

func (*Conn) WithReader

func (cn *Conn) WithReader(
    ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error,
) error

func (*Conn) WithWriter

func (cn *Conn) WithWriter(
    ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
) error

func (*Conn) Write

func (cn *Conn) Write(b []byte) (int, 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) Remove

func (p *ConnPool) Remove(_ context.Context, cn *Conn, reason error)

func (*ConnPool) Stats

func (p *ConnPool) Stats() *Stats

type Options

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

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

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

func NewSingleConnPool

func NewSingleConnPool(pool Pooler, cn *Conn) *SingleConnPool

func (*SingleConnPool) Close

func (p *SingleConnPool) Close() error

func (*SingleConnPool) CloseConn

func (p *SingleConnPool) CloseConn(cn *Conn) error

func (*SingleConnPool) Get

func (p *SingleConnPool) Get(ctx context.Context) (*Conn, error)

func (*SingleConnPool) IdleLen

func (p *SingleConnPool) IdleLen() int

func (*SingleConnPool) Len

func (p *SingleConnPool) Len() int

func (*SingleConnPool) NewConn

func (p *SingleConnPool) NewConn(ctx context.Context) (*Conn, error)

func (*SingleConnPool) Put

func (p *SingleConnPool) Put(ctx context.Context, cn *Conn)

func (*SingleConnPool) Remove

func (p *SingleConnPool) Remove(ctx context.Context, cn *Conn, reason error)

func (*SingleConnPool) Stats

func (p *SingleConnPool) Stats() *Stats

type 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

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

func NewStickyConnPool

func NewStickyConnPool(pool Pooler) *StickyConnPool

func (*StickyConnPool) Close

func (p *StickyConnPool) Close() error

func (*StickyConnPool) CloseConn

func (p *StickyConnPool) CloseConn(cn *Conn) error

func (*StickyConnPool) Get

func (p *StickyConnPool) Get(ctx context.Context) (*Conn, error)

func (*StickyConnPool) IdleLen

func (p *StickyConnPool) IdleLen() int

func (*StickyConnPool) Len

func (p *StickyConnPool) Len() int

func (*StickyConnPool) NewConn

func (p *StickyConnPool) NewConn(ctx context.Context) (*Conn, error)

func (*StickyConnPool) Put

func (p *StickyConnPool) Put(ctx context.Context, cn *Conn)

func (*StickyConnPool) Remove

func (p *StickyConnPool) Remove(ctx context.Context, cn *Conn, reason error)

func (*StickyConnPool) Reset

func (p *StickyConnPool) Reset(ctx context.Context) error

func (*StickyConnPool) Stats

func (p *StickyConnPool) Stats() *Stats