pool

package
v5.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2016 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed      = errors.New("redis: client is closed")
	ErrPoolTimeout = errors.New("redis: connection pool timeout")
)

Functions

func SetIdleCheckFrequency

func SetIdleCheckFrequency(d time.Duration)

Types

type Conn

type Conn struct {
	NetConn net.Conn
	Rd      *proto.Reader
	Wb      *proto.WriteBuffer

	Inited bool
	UsedAt time.Time

	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

func NewConn

func NewConn(netConn net.Conn) *Conn

func (*Conn) Close

func (cn *Conn) Close() error

func (*Conn) IsStale

func (cn *Conn) IsStale(timeout time.Duration) bool

func (*Conn) Read

func (cn *Conn) Read(b []byte) (int, error)

func (*Conn) RemoteAddr

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

func (*Conn) Write

func (cn *Conn) Write(b []byte) (int, error)

type ConnPool

type ConnPool struct {
	DialLimiter *ratelimit.RateLimiter
	OnClose     func(*Conn) error
	// contains filtered or unexported fields
}

func NewConnPool

func NewConnPool(dial dialer, poolSize int, poolTimeout, idleTimeout, idleCheckFrequency time.Duration) *ConnPool

func (*ConnPool) Close

func (p *ConnPool) Close() (retErr error)

func (*ConnPool) Closed

func (p *ConnPool) Closed() bool

func (*ConnPool) FreeLen

func (p *ConnPool) FreeLen() int

FreeLen returns number of free connections.

func (*ConnPool) Get

func (p *ConnPool) Get() (*Conn, bool, error)

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

func (*ConnPool) Len

func (p *ConnPool) Len() int

Len returns total number of connections.

func (*ConnPool) NewConn

func (p *ConnPool) NewConn() (*Conn, error)

func (*ConnPool) PopFree

func (p *ConnPool) PopFree() *Conn

func (*ConnPool) Put

func (p *ConnPool) Put(cn *Conn) error

func (*ConnPool) ReapStaleConns

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

func (*ConnPool) Remove

func (p *ConnPool) Remove(cn *Conn, reason error) error

func (*ConnPool) Stats

func (p *ConnPool) Stats() *Stats

type Pooler

type Pooler interface {
	Get() (*Conn, bool, error)
	Put(*Conn) error
	Remove(*Conn, error) error
	Len() int
	FreeLen() int
	Stats() *Stats
	Close() error
	Closed() bool
}

type SingleConnPool

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

func NewSingleConnPool

func NewSingleConnPool(cn *Conn) *SingleConnPool

func (*SingleConnPool) Close

func (p *SingleConnPool) Close() error

func (*SingleConnPool) Closed

func (p *SingleConnPool) Closed() bool

func (*SingleConnPool) First

func (p *SingleConnPool) First() *Conn

func (*SingleConnPool) FreeLen

func (p *SingleConnPool) FreeLen() int

func (*SingleConnPool) Get

func (p *SingleConnPool) Get() (*Conn, bool, error)

func (*SingleConnPool) Len

func (p *SingleConnPool) Len() int

func (*SingleConnPool) Put

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

func (*SingleConnPool) Remove

func (p *SingleConnPool) Remove(cn *Conn, _ error) error

func (*SingleConnPool) Stats

func (p *SingleConnPool) Stats() *Stats

type Stats

type Stats struct {
	Requests uint32 // number of times a connection was requested by the pool
	Hits     uint32 // number of times free connection was found in the pool
	Timeouts uint32 // number of times a wait timeout occurred

	TotalConns uint32 // the number of total connections in the pool
	FreeConns  uint32 // the number of free connections in the pool
}

Stats contains pool state information and accumulated stats.

type StickyConnPool

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

func NewStickyConnPool

func NewStickyConnPool(pool *ConnPool, reusable bool) *StickyConnPool

func (*StickyConnPool) Close

func (p *StickyConnPool) Close() error

func (*StickyConnPool) Closed

func (p *StickyConnPool) Closed() bool

func (*StickyConnPool) First

func (p *StickyConnPool) First() *Conn

func (*StickyConnPool) FreeLen

func (p *StickyConnPool) FreeLen() int

func (*StickyConnPool) Get

func (p *StickyConnPool) Get() (*Conn, bool, error)

func (*StickyConnPool) Len

func (p *StickyConnPool) Len() int

func (*StickyConnPool) Put

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

func (*StickyConnPool) Remove

func (p *StickyConnPool) Remove(cn *Conn, reason error) error

func (*StickyConnPool) Stats

func (p *StickyConnPool) Stats() *Stats

Jump to

Keyboard shortcuts

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