Documentation ¶
Overview ¶
Package goredis is a client for the redis and ledisdb.
Client ¶
The client is the primary interface for redis. You must first create a client with redis address for working.
c := NewClient("127.0.0.1:6380")
The most important function for client is Do function to send commands to remote server.
reply, err := c.Do("ping") reply, err := c.Do("set", "key", "value") reply, err := c.Do("get", "key")
Connection ¶
You can use an independent connection to send commands.
//get a connection conn, _ := c.Get() //connection send command conn.Do("ping")
Reply Helper ¶
You can use reply helper to convert a reply to a specific type.
exists, err := Bool(c.Do("exists", "key")) score, err := Int64(c.Do("zscore", "key", "member"))
Index ¶
- Variables
- func Bool(reply interface{}, err error) (bool, error)
- func Bytes(reply interface{}, err error) ([]byte, error)
- func Float64(reply interface{}, err error) (float64, error)
- func Int(reply interface{}, err error) (int, error)
- func Int64(reply interface{}, err error) (int64, error)
- func MultiBulk(reply interface{}, err error) ([]interface{}, error)
- func String(reply interface{}, err error) (string, error)
- func Strings(reply interface{}, err error) ([]string, error)
- func Uint64(reply interface{}, err error) (uint64, error)
- func Values(reply interface{}, err error) ([]interface{}, error)
- type Client
- func (c *Client) Close()
- func (c *Client) Do(cmd string, args ...interface{}) (interface{}, error)
- func (c *Client) Get() (*PoolConn, error)
- func (c *Client) SetMaxIdleConns(n int)
- func (c *Client) SetPassword(pass string)
- func (c *Client) SetReadBufferSize(s int)
- func (c *Client) SetWriteBufferSize(s int)
- type Conn
- func (c *Conn) Close()
- func (c *Conn) Do(cmd string, args ...interface{}) (interface{}, error)
- func (c *Conn) GetTotalReadSize() int64
- func (c *Conn) GetTotalWriteSize() int64
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Receive() (interface{}, error)
- func (c *Conn) ReceiveBulkTo(w io.Writer) error
- func (c *Conn) ReceiveRequest() ([][]byte, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) Send(cmd string, args ...interface{}) error
- func (c *Conn) SendValue(v interface{}) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- type Error
- type PoolConn
- type RespReader
- type RespWriter
- func (resp *RespWriter) Flush() error
- func (resp *RespWriter) FlushArray(ay []interface{}) error
- func (resp *RespWriter) FlushBulk(b []byte) error
- func (resp *RespWriter) FlushError(e error) error
- func (resp *RespWriter) FlushInteger(n int64) error
- func (resp *RespWriter) FlushString(s string) error
- func (resp *RespWriter) WriteArray(ay []interface{}) error
- func (resp *RespWriter) WriteBulk(b []byte) error
- func (resp *RespWriter) WriteCommand(cmd string, args ...interface{}) error
- func (resp *RespWriter) WriteError(e error) error
- func (resp *RespWriter) WriteInteger(n int64) error
- func (resp *RespWriter) WriteString(s string) error
Constants ¶
This section is empty.
Variables ¶
var ErrNil = errors.New("nil returned")
ErrNil indicates that a reply value is nil.
Functions ¶
func Bool ¶
Bool is a helper that converts a command reply to a boolean. If err is not equal to nil, then Bool returns false, err. Otherwise Bool converts the reply to boolean as follows:
Reply type Result integer value != 0, nil bulk string strconv.ParseBool(reply) nil false, ErrNil other false, error
func Bytes ¶
Bytes is a helper that converts a command reply to a slice of bytes. If err is not equal to nil, then Bytes returns nil, err. Otherwise Bytes converts the reply to a slice of bytes as follows:
Reply type Result bulk string reply, nil simple string []byte(reply), nil nil nil, ErrNil other nil, error
func Float64 ¶
Float64 is a helper that converts a command reply to 64 bit float. If err is not equal to nil, then Float64 returns 0, err. Otherwise, Float64 converts the reply to an int as follows:
Reply type Result bulk string parsed reply, nil nil 0, ErrNil other 0, error
func Int ¶
Int is a helper that converts a command reply to an integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int converts the reply to an int as follows:
Reply type Result integer int(reply), nil bulk string parsed reply, nil nil 0, ErrNil other 0, error
func Int64 ¶
Int64 is a helper that converts a command reply to 64 bit integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the reply to an int64 as follows:
Reply type Result integer reply, nil bulk string parsed reply, nil nil 0, ErrNil other 0, error
func String ¶
String is a helper that converts a command reply to a string. If err is not equal to nil, then String returns "", err. Otherwise String converts the reply to a string as follows:
Reply type Result bulk string string(reply), nil simple string reply, nil nil "", ErrNil other "", error
func Strings ¶
Strings is a helper that converts an array command reply to a []string. If err is not equal to nil, then Strings returns nil, err. If one of the array items is not a bulk string or nil, then Strings returns an error.
func Uint64 ¶
Uint64 is a helper that converts a command reply to 64 bit integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the reply to an int64 as follows:
Reply type Result integer reply, nil bulk string parsed reply, nil nil 0, ErrNil other 0, error
Types ¶
type Client ¶
func (*Client) SetMaxIdleConns ¶
func (*Client) SetPassword ¶
func (*Client) SetReadBufferSize ¶
func (*Client) SetWriteBufferSize ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func ConnectWithSize ¶
func NewConnWithSize ¶
func (*Conn) GetTotalReadSize ¶
func (*Conn) GetTotalWriteSize ¶
func (*Conn) ReceiveBulkTo ¶
Receive RESP bulk string reply into writer w
func (*Conn) ReceiveRequest ¶
Receive RESP command request, must array of bulk stirng
func (*Conn) RemoteAddr ¶
type RespReader ¶
type RespReader struct {
// contains filtered or unexported fields
}
func NewRespReader ¶
func NewRespReader(br *bufio.Reader) *RespReader
func (*RespReader) ParseBulkTo ¶
func (resp *RespReader) ParseBulkTo(w io.Writer) error
Parse bulk string and write it with writer w
func (*RespReader) ParseRequest ¶
func (resp *RespReader) ParseRequest() ([][]byte, error)
Parse client -> server command request, must be array of bulk strings
type RespWriter ¶
type RespWriter struct {
// contains filtered or unexported fields
}
func NewRespWriter ¶
func NewRespWriter(bw *bufio.Writer) *RespWriter
func (*RespWriter) Flush ¶
func (resp *RespWriter) Flush() error
func (*RespWriter) FlushArray ¶
func (resp *RespWriter) FlushArray(ay []interface{}) error
func (*RespWriter) FlushBulk ¶
func (resp *RespWriter) FlushBulk(b []byte) error
func (*RespWriter) FlushError ¶
func (resp *RespWriter) FlushError(e error) error
func (*RespWriter) FlushInteger ¶
func (resp *RespWriter) FlushInteger(n int64) error
func (*RespWriter) FlushString ¶
func (resp *RespWriter) FlushString(s string) error
func (*RespWriter) WriteArray ¶
func (resp *RespWriter) WriteArray(ay []interface{}) error
func (*RespWriter) WriteBulk ¶
func (resp *RespWriter) WriteBulk(b []byte) error
func (*RespWriter) WriteCommand ¶
func (resp *RespWriter) WriteCommand(cmd string, args ...interface{}) error
RESP command is array of bulk string
func (*RespWriter) WriteError ¶
func (resp *RespWriter) WriteError(e error) error
func (*RespWriter) WriteInteger ¶
func (resp *RespWriter) WriteInteger(n int64) error
func (*RespWriter) WriteString ¶
func (resp *RespWriter) WriteString(s string) error