Documentation ¶
Overview ¶
Package redispool exposes a single RedisConnection object with wrapped access to a single redis connection, and a ConnectionPool object to pool these RedisConnections.
Index ¶
- Variables
- type Conn
- type ConnectionPool
- func (cp *ConnectionPool) Available() int64
- func (cp *ConnectionPool) Capacity() int64
- func (cp *ConnectionPool) Close()
- func (cp *ConnectionPool) Get() (PoolConnection, error)
- func (cp *ConnectionPool) IdleTimeout() time.Duration
- func (cp *ConnectionPool) MaxCap() int64
- func (cp *ConnectionPool) Open(connFactory CreateConnectionFunc)
- func (cp *ConnectionPool) Put(conn PoolConnection)
- func (cp *ConnectionPool) SetCapacity(capacity int) (err error)
- func (cp *ConnectionPool) SetIdleTimeout(idleTimeout time.Duration)
- func (cp *ConnectionPool) StatsJSON() string
- func (cp *ConnectionPool) TryGet() (PoolConnection, error)
- func (cp *ConnectionPool) WaitCount() int64
- func (cp *ConnectionPool) WaitTime() time.Duration
- type CreateConnectionFunc
- type IPool
- type PoolConnection
- type PooledConn
Constants ¶
This section is empty.
Variables ¶
var (
CONN_POOL_CLOSED_ERR = errors.New("connection pool is closed")
)
Functions ¶
This section is empty.
Types ¶
type ConnectionPool ¶
type ConnectionPool struct {
// contains filtered or unexported fields
}
ConnectionPool re-exposes ResourcePool as a pool of PoolConnection objects
func NewConnectionPool ¶
func NewConnectionPool(name string, capacity int, idleTimeout time.Duration) *ConnectionPool
NewConnectionPool creates a new ConnectionPool. The name is used to publish stats only.
func (*ConnectionPool) Available ¶
func (cp *ConnectionPool) Available() int64
Available returns the number of available connections in the pool
func (*ConnectionPool) Capacity ¶
func (cp *ConnectionPool) Capacity() int64
Capacity returns the pool capacity.
func (*ConnectionPool) Close ¶
func (cp *ConnectionPool) Close()
Close will close the pool and wait for connections to be returned before exiting.
func (*ConnectionPool) Get ¶
func (cp *ConnectionPool) Get() (PoolConnection, error)
Get returns a connection. You must call Recycle on the PoolConnection once done.
func (*ConnectionPool) IdleTimeout ¶
func (cp *ConnectionPool) IdleTimeout() time.Duration
IdleTimeout returns the idle timeout for the pool.
func (*ConnectionPool) MaxCap ¶
func (cp *ConnectionPool) MaxCap() int64
MaxCap returns the maximum size of the pool
func (*ConnectionPool) Open ¶
func (cp *ConnectionPool) Open(connFactory CreateConnectionFunc)
Open must be call before starting to use the pool.
func (*ConnectionPool) Put ¶
func (cp *ConnectionPool) Put(conn PoolConnection)
Put puts a connection into the pool.
func (*ConnectionPool) SetCapacity ¶
func (cp *ConnectionPool) SetCapacity(capacity int) (err error)
SetCapacity alters the size of the pool at runtime.
func (*ConnectionPool) SetIdleTimeout ¶
func (cp *ConnectionPool) SetIdleTimeout(idleTimeout time.Duration)
SetIdleTimeout sets the idleTimeout on the pool.
func (*ConnectionPool) StatsJSON ¶
func (cp *ConnectionPool) StatsJSON() string
StatsJSON returns the pool stats as a JSOn object.
func (*ConnectionPool) TryGet ¶
func (cp *ConnectionPool) TryGet() (PoolConnection, error)
TryGet returns a connection, or nil. You must call Recycle on the PoolConnection once done.
func (*ConnectionPool) WaitCount ¶
func (cp *ConnectionPool) WaitCount() int64
WaitCount returns how many clients are waiting for a connection
func (*ConnectionPool) WaitTime ¶
func (cp *ConnectionPool) WaitTime() time.Duration
WaitTime return the pool WaitTime.
type CreateConnectionFunc ¶
type CreateConnectionFunc func(pool IPool) (connection PoolConnection, err error)
CreateConnectionFunc is the factory method to create new connections within the passed ConnectionPool.
func ConnectionCreator ¶
func ConnectionCreator(addr string) CreateConnectionFunc
type IPool ¶
type IPool interface { Put(conn PoolConnection) Get() (PoolConnection, error) Open(fact CreateConnectionFunc) Close() }
type PoolConnection ¶
type PoolConnection interface { Close() IsClosed() bool Recycle() }
PoolConnection is the interface implemented by users of this specialized pool.
type PooledConn ¶
type PooledConn struct { *Conn // contains filtered or unexported fields }
func (*PooledConn) BufioReader ¶
func (pc *PooledConn) BufioReader() *bufio.Reader
func (*PooledConn) Read ¶
func (pc *PooledConn) Read(p []byte) (int, error)
requre read to use bufio
func (*PooledConn) Recycle ¶
func (pc *PooledConn) Recycle()