Documentation ¶
Overview ¶
Package rmux/connection provides a way to open outbound connections to redis servers. Connections are aware of redis databases and subscriptions, and come with a connectionPool for recycling.
Index ¶
- Constants
- Variables
- type Connection
- type ConnectionPool
- func (cp *ConnectionPool) CheckConnectionState() (isUp bool)
- func (cp *ConnectionPool) CreateConnection() *Connection
- func (cp *ConnectionPool) GetConnection() (connection *Connection, err error)
- func (cp *ConnectionPool) IsConnected() bool
- func (myConnectionPool *ConnectionPool) RecycleRemoteConnection(remoteConnection *Connection)
- func (cp *ConnectionPool) ReportGraphite()
- func (cp *ConnectionPool) SetIsConnected(isConnected bool)
- type HashRing
Constants ¶
const ( //Default connect timeout, for connection pools. Can be adjusted on individual pools after initialization EXTERN_CONNECT_TIMEOUT = time.Millisecond * 500 //Default read timeout, for connection pools. Can be adjusted on individual pools after initialization EXTERN_READ_TIMEOUT = time.Millisecond * 500 //Default write timeout, for connection pools. Can be adjusted on individual pools after initialization EXTERN_WRITE_TIMEOUT = time.Millisecond * 500 )
Variables ¶
var ERR_HASHRING_DOWN = errors.New("Hash ring is down")
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct { //The database that we are currently connected to DatabaseId int // The reader from the redis server Reader *bufio.Reader // The writer to the redis server Writer *FlexibleWriter // contains filtered or unexported fields }
An outbound connection to a redis server Maintains its own underlying TimedNetReadWriter, and keeps track of its DatabaseId for select() changes
func NewConnection ¶
func NewConnection(Protocol, Endpoint string, ConnectTimeout, ReadTimeout, WriteTimeout time.Duration) *Connection
Initializes a new connection, of the given protocol and endpoint, with the given connection timeout ex: "unix", "/tmp/myAwesomeSocket", 50*time.Millisecond
func (*Connection) CheckConnection ¶
func (myConnection *Connection) CheckConnection() bool
Checks if the current connection is up or not If we do not get a response, or if we do not get a PONG reply, or if there is any error, returns false
func (*Connection) Disconnect ¶
func (c *Connection) Disconnect()
func (*Connection) IsConnected ¶
func (c *Connection) IsConnected() bool
func (*Connection) ReconnectIfNecessary ¶
func (c *Connection) ReconnectIfNecessary() (err error)
func (*Connection) SelectDatabase ¶
func (this *Connection) SelectDatabase(DatabaseId int) (err error)
Selects the given database, for the connection If an error is returned, or if an invalid response is returned from the select, then this will return an error If not, the connections internal database will be updated accordingly
type ConnectionPool ¶
type ConnectionPool struct { //The protocol to use for our connections (unix/tcp/udp) Protocol string //The endpoint to connect to Endpoint string //And overridable connect timeout. Defaults to EXTERN_CONNECT_TIMEOUT ConnectTimeout time.Duration //An overridable read timeout. Defaults to EXTERN_READ_TIMEOUT ReadTimeout time.Duration //An overridable write timeout. Defaults to EXTERN_WRITE_TIMEOUT WriteTimeout time.Duration // Number of active connections Count int32 // contains filtered or unexported fields }
A pool of connections to a single outbound redis server
func NewConnectionPool ¶
func NewConnectionPool(Protocol, Endpoint string, poolCapacity int, connectTimeout time.Duration, readTimeout time.Duration, writeTimeout time.Duration) (newConnectionPool *ConnectionPool)
Initialize a new connection pool, for the given protocol/endpoint, with a given pool capacity ex: "unix", "/tmp/myAwesomeSocket", 5
func (*ConnectionPool) CheckConnectionState ¶
func (cp *ConnectionPool) CheckConnectionState() (isUp bool)
Checks the state of connections in this connection pool If a remote server has severe lag, mysteriously goes away, or stops responding all-together, returns false
func (*ConnectionPool) CreateConnection ¶
func (cp *ConnectionPool) CreateConnection() *Connection
Creates a new Connection basead on the pool's configuration
func (*ConnectionPool) GetConnection ¶
func (cp *ConnectionPool) GetConnection() (connection *Connection, err error)
Gets a connection from the connection pool
func (*ConnectionPool) IsConnected ¶
func (cp *ConnectionPool) IsConnected() bool
func (*ConnectionPool) RecycleRemoteConnection ¶
func (myConnectionPool *ConnectionPool) RecycleRemoteConnection(remoteConnection *Connection)
Recycles a connection back into our connection pool If the pool is full, throws it away
func (*ConnectionPool) ReportGraphite ¶
func (cp *ConnectionPool) ReportGraphite()
func (*ConnectionPool) SetIsConnected ¶
func (cp *ConnectionPool) SetIsConnected(isConnected bool)
type HashRing ¶
type HashRing struct { //The connection pools that we will be hashing our connections to ConnectionPools []*ConnectionPool //The bitmask to use for all hashed queries BitMask uint32 //The default connection pool DefaultConnectionPool *ConnectionPool // Whether to failover to next pool when the desired one is down Failover bool }
An outbound connection to a redis server Maintains its own underlying TimedNetReadWriter, and keeps track of its DatabaseId for select() changes
func NewHashRing ¶
func NewHashRing(connectionPools []*ConnectionPool, failover bool) (newHashRing *HashRing, err error)
func (*HashRing) GetConnectionPool ¶
func (myHashRing *HashRing) GetConnectionPool(command protocol.Command) (connectionPool *ConnectionPool, err error)
Gets the connectionKey, for a to-be-multiplexed command Uses the bernstein hash, which is one of the fastest key-distribution algorithms out there