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 ¶
- func AppendArbitrary(buf []byte, m interface{}) []byte
- func AppendArbitraryAsFlattenedStrings(buf []byte, m interface{}) []byte
- func AppendArbitraryAsStrings(buf []byte, m interface{}) []byte
- 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 Message
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendArbitrary ¶ added in v0.5.5
AppendArbitrary takes in any primitive golang value, or Message, and appends its encoded form to the given buffer, inferring types where appropriate. It then returns the appended buffer
func AppendArbitraryAsFlattenedStrings ¶ added in v0.5.5
AppendArbitraryAsFlattenedStrings is similar to AppendArbitrary 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 AppendArbitraryAsStrings ¶ added in v0.5.5
AppendArbitraryAsString is similar to AppendArbitraryAsFlattenedString except that it won't flatten any embedded arrays.
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 ¶ added in v0.4.2
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 ¶ added in v0.5.0
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