Documentation ¶
Overview ¶
Package rmux provides a connection-pooling, multiplexing redis server. Commands are parsed, and multiplexed out based on their arguments. Package rmux/main includes a working server implementation, if no customization is needed
Index ¶
- Variables
- type Client
- func (this *Client) FlushError(err error) error
- func (this *Client) FlushLine(line []byte) (err error)
- func (this *Client) FlushRedisAndRespond() error
- func (this *Client) HasBufferedOutput() bool
- func (this *Client) HasQueued() bool
- func (this *Client) ParseCommand(command protocol.Command) ([]byte, error)
- func (this *Client) Queue(command protocol.Command)
- func (this *Client) ReadLoop(rmux *RedisMultiplexer)
- func (this *Client) WriteError(err error, flush bool) error
- func (this *Client) WriteLine(line []byte) (err error)
- type RedisMultiplexer
- func (this *RedisMultiplexer) AddConnection(remoteProtocol, remoteEndpoint string)
- func (this *RedisMultiplexer) GraphiteCheckin()
- func (this *RedisMultiplexer) HandleClientRequests(client *Client)
- func (this *RedisMultiplexer) HandleCommand(client *Client, command protocol.Command)
- func (this *RedisMultiplexer) HandleCommandChunk(client *Client, command protocol.Command)
- func (this *RedisMultiplexer) HandleError(client *Client, err error)
- func (rm *RedisMultiplexer) SetAllTimeouts(t time.Duration)
- func (this *RedisMultiplexer) Start() (err error)
Constants ¶
This section is empty.
Variables ¶
var ( ERR_QUIT = errors.New("Client asked to quit") ERR_CONNECTION_DOWN = errors.New(string(CONNECTION_DOWN_RESPONSE)) ERR_TIMEOUT = errors.New("Proxy timeout") )
var ( //Response code for when a command (that operates on multiple keys) is used on a server that is multiplexing MULTIPLEX_OPERATION_UNSUPPORTED_RESPONSE = []byte("This command is not supported for multiplexing servers") //Response code for when a client can't connect to any target servers CONNECTION_DOWN_RESPONSE = []byte("Connection down") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { //The underlying ReadWriter for this connection Writer *FlexibleWriter //Whether or not this client needs to consider multiplexing Multiplexing bool Connection net.Conn //The Database that our client thinks we're connected to DatabaseId int //Whether or not this client connection is active or not //Upon QUIT command, this gets toggled off Active bool ReadChannel chan readItem HashRing *connection.HashRing Scanner *protocol.RespScanner // contains filtered or unexported fields }
Represents a redis client that is connected to our rmux server
func NewClient ¶
func NewClient(connection net.Conn, readTimeout, writeTimeout time.Duration, isMuliplexing bool, hashRing *connection.HashRing) (newClient *Client)
Initializes a new client, for the given established net connection, with the specified read/write timeouts
func (*Client) FlushError ¶
func (*Client) FlushRedisAndRespond ¶
Performs the query against the redis server and responds to the connected client with the response from redis.
func (*Client) HasBufferedOutput ¶
func (*Client) ParseCommand ¶
Parses the given command
func (*Client) ReadLoop ¶
func (this *Client) ReadLoop(rmux *RedisMultiplexer)
Read loop for this client - moves commands and channels to the worker loop
type RedisMultiplexer ¶
type RedisMultiplexer struct { HashRing *connection.HashRing //hashmap of [connection endpoint] -> connectionPools ConnectionCluster []*connection.ConnectionPool //The net.listener for our server Listener net.Listener //The amount of connections to store, in each of our connectionpools PoolSize int //The primary connection key to use. If we're not operating on a key-based operation, it will go here PrimaryConnectionPool *connection.ConnectionPool //And overridable connect timeout. Defaults to EXTERN_CONNECT_TIMEOUT EndpointConnectTimeout time.Duration //An overridable read timeout. Defaults to EXTERN_READ_TIMEOUT EndpointReadTimeout time.Duration //An overridable write timeout. Defaults to EXTERN_WRITE_TIMEOUT EndpointWriteTimeout time.Duration //An overridable read timeout. Defaults to EXTERN_READ_TIMEOUT ClientReadTimeout time.Duration //An overridable write timeout. Defaults to EXTERN_WRITE_TIMEOUT ClientWriteTimeout time.Duration // The graphite statsd server to ping with metrics GraphiteServer *string // Whether to failover to another connection pool if the target connection pool is down (in multiplexing mode) Failover bool // contains filtered or unexported fields }
The main RedisMultiplexer Listens on a specified socket or port, and assigns out queries to any number of connection pools If more than one connection pool is given multi-key operations are blocked
func NewRedisMultiplexer ¶
func NewRedisMultiplexer(listenProtocol, listenEndpoint string, poolSize int) (newRedisMultiplexer *RedisMultiplexer, err error)
Initializes a new redis multiplexer, listening on the given protocol/endpoint, with a set connectionPool size ex: "unix", "/tmp/myAwesomeSocket", 50
func (*RedisMultiplexer) AddConnection ¶
func (this *RedisMultiplexer) AddConnection(remoteProtocol, remoteEndpoint string)
Adds a connection to the redis multiplexer, for the given protocol and endpoint
func (*RedisMultiplexer) GraphiteCheckin ¶
func (this *RedisMultiplexer) GraphiteCheckin()
func (*RedisMultiplexer) HandleClientRequests ¶
func (this *RedisMultiplexer) HandleClientRequests(client *Client)
Handles requests for a client. Inspects all incoming commands, to find if they are key-driven or not. If they are, finds the appropriate connection pool, and passes the request off to it.
func (*RedisMultiplexer) HandleCommand ¶
func (this *RedisMultiplexer) HandleCommand(client *Client, command protocol.Command)
func (*RedisMultiplexer) HandleCommandChunk ¶
func (this *RedisMultiplexer) HandleCommandChunk(client *Client, command protocol.Command)
This looks a lot like HandleClientRequests above, but will break and flush to redis if there is nothing to read. Will allow it to handle a pipeline of commands without spinning indefinitely.
func (*RedisMultiplexer) HandleError ¶
func (this *RedisMultiplexer) HandleError(client *Client, err error)
func (*RedisMultiplexer) SetAllTimeouts ¶
func (rm *RedisMultiplexer) SetAllTimeouts(t time.Duration)
func (*RedisMultiplexer) Start ¶
func (this *RedisMultiplexer) Start() (err error)
Called when a rmux server is ready to begin accepting connections
Directories ¶
Path | Synopsis |
---|---|
Package rmux/connection provides a way to open outbound connections to redis servers.
|
Package rmux/connection provides a way to open outbound connections to redis servers. |
Package rmux/protocol provides a standard way to listen in on the redis protocol, look ahead to what commands are about to be executed, and ignore them or pass them on to another buffer, as desired
|
Package rmux/protocol provides a standard way to listen in on the redis protocol, look ahead to what commands are about to be executed, and ignore them or pass them on to another buffer, as desired |