Documentation
¶
Overview ¶
Package resp implements the protocol of RESP(REdis Serialization Protocol)
Index ¶
- func IsTimeout(r *Resp) bool
- type Resp
- func (r *Resp) Array() ([]*Resp, error)
- func (r *Resp) Bytes() ([]byte, error)
- func (r *Resp) Float64() (float64, error)
- func (r *Resp) Int() (int, error)
- func (r *Resp) Int64() (int64, error)
- func (r *Resp) IsType(t RespType) bool
- func (r *Resp) List() ([]string, error)
- func (r *Resp) ListBytes() ([][]byte, error)
- func (r *Resp) Map() (map[string]string, error)
- func (r *Resp) Str() (string, error)
- func (r *Resp) String() string
- func (r *Resp) WriteTo(w io.Writer) (int64, error)
- type RespReader
- type RespType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Resp ¶
type Resp struct { Typ RespType Val interface{} // Err indicates that this Resp signals some kind of error, either on the // connection level or the application level. Use IsType if you need to // determine which, otherwise you can simply check if this is nil Err error }
Resp represents a single response or message being sent to/from a redis server. Each Resp has a type (see RespType and IsType) and a value. Values can be retrieved using any of the casting methods on this type (e.g. Str)
func NewResp ¶
func NewResp(v interface{}) *Resp
NewResp takes the given value and interprets it into a resp encoded byte stream
func NewRespErr ¶
NewRespErr is a convenience method for making Resps to wrap errors
func NewRespFlattenedStrings ¶
func NewRespFlattenedStrings(v interface{}) *Resp
NewRespFlattenedStrings is like NewResp except it looks through the given value and converts any types (except slices/maps) into strings, and flatten any embedded slices/maps into a single slice. 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/map it will be wrapped so that it is written as a Array of size one
func NewRespIOErr ¶
NewRespIOErr is a convenience method for making Resps to wrap io errors
func NewRespSimple ¶
NewRespSimple is like NewResp except it encodes its string as a resp SimpleStr type, whereas NewResp will encode all strings as BulkStr
func (*Resp) Array ¶
Array returns the Resp slice encompassed by this Resp. Only valid for a Resp of type Array. If r.Err != nil that will be returned
func (*Resp) Bytes ¶
Bytes returns a byte slice representing the value of the Resp. Only valid for a Resp of type Str. If r.Err != nil that will be returned.
func (*Resp) Float64 ¶
Float64 returns a float64 representing the value of the Resp. Only valud for a Resp of type Str which represents an actual float. If r.Err != nil that will be returned
func (*Resp) Int ¶
Int returns an int representing the value of the Resp. For a Resp of type Int the integer value will be returned directly. For a Resp of type Str the string will attempt to be parsed as a base-10 integer, returning the parsing error if any. If r.Err != nil that will be returned
func (*Resp) IsType ¶
IsType returns whether or or not the reply is of a given type
isStr := r.IsType(redis.Str)
Multiple types can be checked at the same time by or'ing the desired types
isStrOrInt := r.IsType(redis.Str | redis.Int)
func (*Resp) List ¶
List is a wrapper around Array which returns the result as a list of strings, calling Str() on each Resp which Array returns. Any errors encountered are immediately returned. Any Nil replies are interpreted as empty strings
func (*Resp) ListBytes ¶
ListBytes is a wrapper around Array which returns the result as a list of byte slices, calling Bytes() on each Resp which Array returns. Any errors encountered are immediately returned. Any Nil replies are interpreted as nil
func (*Resp) Map ¶
Map is a wrapper around Array which returns the result as a map of strings, calling Str() on alternating key/values for the map. All value fields of type Nil will be treated as empty strings, keys must all be of type Str
func (*Resp) Str ¶
Str is a wrapper around Bytes which returns the result as a string instead of a byte slice
type RespReader ¶
type RespReader struct {
// contains filtered or unexported fields
}
RespReader is a wrapper around an io.Reader which will read Resp messages off of the io.Reader
func NewRespReader ¶
func NewRespReader(r io.Reader) *RespReader
NewRespReader creates and returns a new RespReader which will read from the given io.Reader. Once passed in the io.Reader shouldn't be read from by any other processes
func (*RespReader) Read ¶
func (rr *RespReader) Read() *Resp
ReadResp attempts to read a message object from the given io.Reader, parse it, and return a Resp representing it
type RespType ¶
type RespType int
RespType is a field on every Resp which indicates the type of the data it contains
const ( // RESP Simple Strings SimpleStr RespType = 1 << iota // RESP Bulk Strings BulkStr // An error which prevented reading/writing, e.g. connection close IOErr // RESP Errors, an error returned by redis, e.g. WRONGTYPE AppErr // RESP Integers Int // RESP Arrays Array // Null Bulk String Nil // Str combines both SimpleStr and BulkStr, which are considered strings to // the Str() method. This is what you want to give to IsType when // determining if a response is a string Str = SimpleStr | BulkStr // Err combines both IOErr and AppErr, which both indicate that the Err // field on their Resp is filled. To determine if a Resp is an error you'll // most often want to simply check if the Err field on it is nil Err = IOErr | AppErr )
Different RespTypes. You can check if a message is of one or more types using the IsType method on Resp @ref http://redis.io/topics/protocol