fixedpool

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DialFunc

type DialFunc func(network, addr string) (*redis.Client, error)

DialFunc is a function which can be passed into NewCustom

type Pool

type Pool struct {

	// The network/address that the pool is connecting to. These are going to be
	// whatever was passed into the New function. These should not be
	// changed after the pool is initialized
	Network, Addr string
	// contains filtered or unexported fields
}

Pool is a simple connection pool for redis Clients. It will create a small pool of initial connections, and if more connections are needed they will be created on demand. If a connection is Put back and the pool is full it will be closed.

func New

func New(network, addr string, size int) (*Pool, error)

New creates a new Pool whose connections are all created using redis.Dial(network, addr). The size indicates the maximum number of idle connections to have waiting to be used at any given moment. If an error is encountered an empty (but still usable) pool is returned alongside that error

func NewCustom

func NewCustom(network, addr string, size int, df DialFunc) (*Pool, error)

NewCustom is like New except you can specify a DialFunc which will be used when creating new connections for the pool. The common use-case is to do authentication for new connections.

func (*Pool) Avail

func (p *Pool) Avail() int

Avail returns the number of connections currently available to be gotten from the Pool using Get. If the number is zero then subsequent calls to Get will be creating new connections on the fly

func (*Pool) Cmd

func (p *Pool) Cmd(cmd string, args ...interface{}) *redis.Resp

Cmd automatically gets one client from the pool, executes the given command (returning its result), and puts the client back in the pool

func (*Pool) Empty

func (p *Pool) Empty()

Empty removes and calls Close() on all the connections currently in the pool. Assuming there are no other connections waiting to be Put back this method effectively closes and cleans up the pool.

func (*Pool) Get

func (p *Pool) Get() (*redis.Client, error)

Get retrieves an available redis client. If there are none available it will create a new one on the fly

func (*Pool) Put

func (p *Pool) Put(conn *redis.Client)

Put returns a client back to the pool. If the pool is full the client is closed instead. If the client is already closed (due to connection failure or what-have-you) it will not be put back in the pool

Jump to

Keyboard shortcuts

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