Documentation ¶
Index ¶
- Constants
- Variables
- func StartServer(port uint, buckets uint)
- type Connection
- func (sc *Connection) Close() error
- func (sc *Connection) Delete(key string) string
- func (sc *Connection) Get(key string) string
- func (sc *Connection) Publish(key, value string) string
- func (sc *Connection) Set(key, value string) string
- func (sc *Connection) Subscribe(key string, recv chan<- string)
- type ConnectionPool
- type Message
- type ProtocolError
Constants ¶
const ( // EOM denotes the end of a message EOM = byte(0) // SEP denotes a delimitor between message units SEP = byte(30) // GET denotes a get-value-at-key command GET = byte('g') // SET denotes a set-key-to-value command SET = byte('s') // DEL denotes a delete-key command DEL = byte('d') // PUB denotes a publish command PUB = byte('P') // SUB denotes a subscribe command SUB = byte('S') // SUCCESS denotes a successful client command SUCCESS = byte('1') // FAIL denotes a failed client command FAIL = byte('0') )
Variables ¶
COMMANDS is a list of all valid commands. The order is important: commands with index less than 3 (GET, DEL, SUB) require one additional argument (a key). Commands with index greater than or equal to 3 (SET, PUB) require two arguments (key, value). The index is used in Parse.
Functions ¶
func StartServer ¶
StartServer starts up a listened at 127.0.0.1:<port> with a key space distributed over a given number of buckets.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
The Connection struct defines an individual client connection.
func NewConnection ¶
func NewConnection(address string, port uint) (*Connection, error)
NewConnection returns a connection to a given address and port number.
func (*Connection) Delete ¶
func (sc *Connection) Delete(key string) string
Delete removes a key-value pair from the database.
func (*Connection) Get ¶
func (sc *Connection) Get(key string) string
Get returns the value associated with a given key.
func (*Connection) Publish ¶
func (sc *Connection) Publish(key, value string) string
Publish sets a value to a key and triggers a subscriber update.
func (*Connection) Set ¶
func (sc *Connection) Set(key, value string) string
Set assigns a value to a key.
func (*Connection) Subscribe ¶
func (sc *Connection) Subscribe(key string, recv chan<- string)
Subscribe added a channel to the subscription list on a key.
type ConnectionPool ¶
type ConnectionPool struct {
// contains filtered or unexported fields
}
The ConnectionPool struct maintains a finite number of connections for use on client-side.
func NewConnectionPool ¶
func NewConnectionPool(address string, port, size uint) *ConnectionPool
NewConnectionPool constructs a ConnectionPool for a given address, port number, and pool size.
func (*ConnectionPool) Connect ¶
func (cp *ConnectionPool) Connect() (*Connection, error)
Connect gets a connection from the pool
func (*ConnectionPool) Free ¶
func (cp *ConnectionPool) Free(c *Connection) error
Free sends a connection back to the pool
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message is the server-side object representation of a client command.
func NewDeleteMessage ¶
NewDeleteMessage constructs a conforming 'del' message
func NewGetMessage ¶
NewGetMessage constructs a conforming 'get' message
func NewPublishMessage ¶
NewPublishMessage constructs a conforming 'pub' message
func NewSetMessage ¶
NewSetMessage constructs a conforming 'set' message
func NewSubscribeMessage ¶
NewSubscribeMessage constructs a conforming 'sub' message
type ProtocolError ¶
type ProtocolError struct {
// contains filtered or unexported fields
}
ProtocolError is the error type for a malformed message.
func (ProtocolError) Error ¶
func (e ProtocolError) Error() string