Documentation ¶
Overview ¶
This package provides an easy to use interface for creating and parsing messages encoded in the REdis Serialization Protocol (RESP). You can check out more details about the protocol here: http://redis.io/topics/protocol
Index ¶
- Constants
- Variables
- func ByteMatcher(b byte) cmux.Matcher
- func DialMsgpack(addr string, timeout time.Duration) (*rpc.Client, error)
- func Marshal(msg interface{}) ([]byte, error)
- func ServeMsgpack(l net.Listener, s *rpc.Server) error
- func ServeRedis(l net.Listener, s *rpc.Server) error
- func Unmarshal(buf []byte, msg interface{}) error
- func WriteArbitrary(w io.Writer, m interface{}) error
- func WriteArbitraryAsFlattenedStrings(w io.Writer, m interface{}) error
- func WriteArbitraryAsString(w io.Writer, m interface{}) error
- func WriteMessage(w io.Writer, m *Message) error
- type Action
- type Item
- type Message
- type Mux
- type RedisServerCodec
- type Reply
- type Request
- type Type
Constants ¶
const ( RaftProto = 0 RpcProto = 1 )
Variables ¶
var (
ErrListenerClosed = errors.New("listener closed")
)
var (
ErrNoLeader = errors.New("no leader")
)
Functions ¶
func ByteMatcher ¶
func WriteArbitrary ¶
WriteArbitrary takes in any primitive golang value, or Message, and writes its encoded form to the given io.Writer, inferring types where appropriate.
func WriteArbitraryAsFlattenedStrings ¶
WriteArbitraryAsFlattenedStrings is similar to WriteArbitrary except that it will encode all types except Array as a BulkStr, converting the argument into a string first as necessary. It will also flatten any embedded arrays into a single long array. This is useful because commands to a redis server must be given as an array of bulk strings. If the argument isn't already in a slice or map it will be wrapped so that it is written as an Array of size one.
Note that if a Message type is found it will *not* be encoded to a BulkStr, but will simply be passed through as whatever type it already represents.
func WriteArbitraryAsString ¶
WriteArbitraryAsString is similar to WriteArbitraryAsFlattenedString except that it won't flatten any embedded arrays.
Types ¶
type Message ¶
type Message struct { Type // contains filtered or unexported fields }
func NewMessage ¶
NewMessagePParses the given raw message and returns a Message struct representing it
func NewSimpleString ¶
Can be used when writing to a resp stream to write a simple-string-style stream (e.g. +OK\r\n) instead of the default bulk-string-style strings.
foo := NewSimpleString("foo") bar := NewSimpleString("bar") baz := NewSimpleString("baz") resp.WriteArbitrary(w, foo) resp.WriteArbitrary(w, []interface{}{bar, baz})
func ReadMessage ¶
ReadMessage attempts to read a message object from the given io.Reader, parse it, and return a Message struct representing it
func (*Message) Array ¶
Array returns the Message slice encompassed by this Messsage, assuming the Message is of type Array
func (*Message) Bytes ¶
Bytes returns a byte slice representing the value of the Message. Only valid for a Message of type SimpleStr, Err, and BulkStr. Others will return an error
func (*Message) Err ¶
Err returns an error representing the value of the Message. Only valid for Err messages
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
func (*Mux) Handle ¶
Handle register a Listener to Mux When a connection reached, Mux will compare first byte to proto, if equal, the corresponding Listener Note: the first byte will consume from connection
func (*Mux) HandleThird ¶
Default will not comsume first byte
type RedisServerCodec ¶
type RedisServerCodec struct {
// contains filtered or unexported fields
}
func NewRedisServerCodec ¶
func NewRedisServerCodec(conn net.Conn) *RedisServerCodec
func (*RedisServerCodec) Close ¶
func (c *RedisServerCodec) Close() error
func (*RedisServerCodec) ReadRequestBody ¶
func (c *RedisServerCodec) ReadRequestBody(x interface{}) error
func (*RedisServerCodec) ReadRequestHeader ¶
func (c *RedisServerCodec) ReadRequestHeader(r *rpc.Request) error
func (*RedisServerCodec) WriteResponse ¶
func (c *RedisServerCodec) WriteResponse(r *rpc.Response, x interface{}) error