Documentation
¶
Index ¶
- Variables
- type Client
- type CmdError
- type Reply
- func (r *Reply) Bool() (bool, error)
- func (r *Reply) Bytes() ([]byte, error)
- func (r *Reply) Hash() (map[string]string, error)
- func (r *Reply) Int() (int, error)
- func (r *Reply) Int64() (int64, error)
- func (r *Reply) List() ([]string, error)
- func (r *Reply) ListBytes() ([][]byte, error)
- func (r *Reply) Str() (string, error)
- func (r *Reply) String() string
- type ReplyType
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // The connection the client talks to redis over. Don't touch this unless // you know what you're doing. Conn net.Conn // contains filtered or unexported fields }
Client describes a Redis client.
func Dial ¶
Dial connects to the given Redis server.
func DialTimeout ¶
Dial connects to the given Redis server with the given timeout.
func (*Client) Append ¶
Append adds the given call to the pipeline queue. Use GetReply() to read the reply.
func (*Client) Cmd ¶
Cmd calls the given Redis command.
func (*Client) GetReply ¶
GetReply returns the reply for the next request in the pipeline queue. Error reply with PipelineQueueEmptyError is returned, if the pipeline queue is empty.
func (*Client) ReadReply ¶
This will read a redis reply off of the connection without sending anything first (useful after you've sent a SUSBSCRIBE command). This will block until a reply is received or the timeout is reached. On timeout an ErrorReply will be returned, you can check if it's a timeout like so:
r := conn.ReadReply() if r.Err != nil { if t, ok := r.Err.(*net.OpError); ok && t.Timeout() { // Is timeout } else { // Not timeout } }
Note: this is a more low-level function, you really shouldn't have to actually use it unless you're writing your own pub/sub code
type CmdError ¶
type CmdError struct {
Err error
}
A CmdError implements the error interface and is what is returned when the server returns an error on the application level (e.g. key doesn't exist or is the wrong type), as opposed to a connection/transport error.
You can test if a reply is a CmdError like so:
r := conn.Cmd("GET", "key-which-isnt-a-string") if r.Err != nil { if cerr, ok := r.Err.(*redis.CmdError); ok { // Is CmdError } else { // Is other error } }
type Reply ¶
type Reply struct { Type ReplyType // Reply type Elems []*Reply // Sub-replies Err error // Reply error // contains filtered or unexported fields }
Reply holds a Redis reply.
func (*Reply) Bool ¶
Bool returns false, if the reply value equals to 0 or "0", otherwise true; or an error, if the reply type is not IntegerReply or BulkReply.
func (*Reply) Bytes ¶
Bytes returns the reply value as a byte string or an error, if the reply type is not StatusReply or BulkReply.
func (*Reply) Hash ¶
Hash returns a multi bulk reply as a map[string]string or an error. The reply type must be MultiReply, it must have an even number of elements, they must be in a "key value key value..." order and values must all be either BulkReply or NilReply. Nil values are returned as empty strings. Useful for hash commands.
func (*Reply) Int ¶
Int is a convenience method for calling Reply.Int64() and converting it to int.
func (*Reply) Int64 ¶
Int64 returns the reply value as a int64 or an error, if the reply type is not IntegerReply or the reply type BulkReply could not be parsed to an int64.
func (*Reply) List ¶
List returns a multi bulk reply as a slice of strings or an error. The reply type must be MultiReply and its elements' types must all be either BulkReply or NilReply. Nil elements are returned as empty strings. Useful for list commands.
func (*Reply) ListBytes ¶
ListBytes returns a multi bulk reply as a slice of bytes slices or an error. The reply type must be MultiReply and its elements' types must all be either BulkReply or NilReply. Nil elements are returned as nil. Useful for list commands.
func (*Reply) Str ¶
Str is a convenience method for calling Reply.Bytes() and converting it to string