Documentation
¶
Overview ¶
Package pool performs key-based sharding over multiple Redis instances.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool maintains a connection pool for multiple Redis instances.
func New ¶
func New( addresses []string, connectTimeout, readTimeout, writeTimeout time.Duration, maxConnectionsPerInstance int, hash func(string) uint32, ) *Pool
New creates and returns a new Pool object.
Addresses are host:port strings for each underlying Redis instance. The number and order of the addresses determines the hash slots, so be careful to make that deterministic.
Connect timeout is the timeout for establishing a connection to any underlying Redis instance. Read timeout is the timeout for reading a reply to a command via an established connection. Write timeout is the timeout for writing a command to an established connection.
Max connections per instance is the size of the connection pool for each Redis instance. Hash defines the hash function used by the With methods. Any function that takes a string and returns a uint32 may be used. Package pool ships with several options, including Murmur3, FNV, and FNVa.
func (*Pool) Close ¶
Close closes all available (idle) connections in the cluster. Close does not affect oustanding (in-use) connections.
func (*Pool) ID ¶
ID returns a unique identifier for the Redis instance represented by index, or an error if the index is invalid.
func (*Pool) Index ¶
Index returns a reference to the connection pool that will be used to satisfy any request for the given key. Pass that value to WithIndex.
func (*Pool) Size ¶
Size returns how many instances the pool sits over. Useful for ranging over with WithIndex.
func (*Pool) With ¶
With is a convenience function that combines Index and WithIndex, for simple/single Redis requests on a single key.
func (*Pool) WithIndex ¶
WithIndex selects a single Redis instance from the referenced connection pool, and then calls the given function with that connection. If the function returns a nil error, WithIndex returns the connection to the pool after it's used. Otherwise, WithIndex discards the connection.
WithIndex will return an error if it wasn't able to successfully retrieve a connection from the referenced connection pool, and will forward any error returned by the `do` function.