redis

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2014 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoadingError error = errors.New("server is busy loading dataset in memory")
View Source
var PipelineQueueEmptyError error = errors.New("pipeline queue empty")

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client describes a Redis client.

func Dial added in v0.4.0

func Dial(network, addr string) (*Client, error)

Dial connects to the given Redis server.

func DialTimeout added in v0.4.0

func DialTimeout(network, addr string, timeout time.Duration) (*Client, error)

Dial connects to the given Redis server with the given timeout.

func (*Client) Append added in v0.2.0

func (c *Client) Append(cmd string, args ...interface{})

Append adds the given call to the pipeline queue. Use GetReply() to read the reply.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) Cmd added in v0.4.0

func (c *Client) Cmd(cmd string, args ...interface{}) *Reply

Cmd calls the given Redis command.

func (*Client) GetReply added in v0.4.0

func (c *Client) GetReply() *Reply

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 added in v0.4.0

func (c *Client) ReadReply() *Reply

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 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

func (r *Reply) Bool() (bool, error)

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

func (r *Reply) Bytes() ([]byte, error)

Bytes returns the reply value as a byte string or an error, if the reply type is not StatusReply or BulkReply.

func (*Reply) Hash added in v0.3.0

func (r *Reply) Hash() (map[string]string, error)

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

func (r *Reply) Int() (int, error)

Int is a convenience method for calling Reply.Int64() and converting it to int.

func (*Reply) Int64

func (r *Reply) Int64() (int64, error)

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 added in v0.3.0

func (r *Reply) List() ([]string, error)

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 added in v0.4.0

func (r *Reply) ListBytes() ([][]byte, error)

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

func (r *Reply) Str() (string, error)

Str is a convenience method for calling Reply.Bytes() and converting it to string

func (*Reply) String

func (r *Reply) String() string

String returns a string representation of the reply and its sub-replies. This method is for debugging. Use method Reply.Str() for reading string reply.

type ReplyType

type ReplyType uint8

ReplyType describes type of a reply.

Possible values are:

StatusReply -- status reply ErrorReply -- error reply IntegerReply -- integer reply NilReply -- nil reply BulkReply -- bulk reply MultiReply -- multi bulk reply

const (
	StatusReply ReplyType = iota
	ErrorReply
	IntegerReply
	NilReply
	BulkReply
	MultiReply
)

Directories

Path Synopsis
This package provides an easy to use interface for creating and parsing messages encoded in the REdis Serialization Protocol (RESP).
This package provides an easy to use interface for creating and parsing messages encoded in the REdis Serialization Protocol (RESP).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL