Documentation ¶
Overview ¶
Package client implements a minimalist client for working with redis servers.
Index ¶
- type Client
- func (c *Client) Del(key string) ([]byte, error)
- func (c *Client) Get(key string) ([]byte, error)
- func (c *Client) Prefix(key string) ([]byte, error)
- func (c *Client) PrefixOnlyKey(key string) ([]byte, error)
- func (c *Client) RecvData() ([]byte, error)
- func (c *Client) Set(key string, value []byte) ([]byte, error)
- type Conn
- type Pool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶ added in v1.0.0
type Conn interface { resp.ResponseParser // MarkFailed marks the connection as failed which // will force it to be closed instead of being returned to the pool MarkFailed() // WriteCmd writes a full command as part of a pipeline. To execute the pipeline, // you must call Flush. WriteCmd(cmd string, args ...[]byte) // WriteCmdString writes a full command as part of a pipeline. To execute the pipeline, // you must call Flush. WriteCmdString(cmd string, args ...string) // WriteMultiBulkSize is a low-level method to write a multibulk size. // For normal operation, use WriteCmd or WriteCmdString. WriteMultiBulkSize(n int) error // WriteBulk is a low-level method to write a bulk. // For normal operation, use WriteCmd or WriteCmdString. WriteBulk(b []byte) // WriteBulkString is a low-level method to write a bulk. // For normal operation, use WriteCmd or WriteCmdString. WriteBulkString(s string) // CopyBulk is a low-level method to copy a large bulk of data directly to the writer. // For normal operation, use WriteCmd or WriteCmdString. CopyBulk(src io.Reader, n int64) error // Flush flushes the output buffer. Call this after you have completed your pipeline Flush() error // SetDeadline sets the read and write deadlines associated // with the connection. It is equivalent to calling both // SetReadDeadline and SetWriteDeadline. SetDeadline(time.Time) error // SetReadDeadline sets the deadline for future Read calls // and any currently-blocked Read call. // A zero value for t means Read will not time out. SetReadDeadline(time.Time) error // SetWriteDeadline sets the deadline for future Write calls // and any currently-blocked Write call. // Even if write times out, it may return n > 0, indicating that // some of the data was successfully written. // A zero value for t means Write will not time out. SetWriteDeadline(time.Time) error // UnreadBytes returns the number of unread bytes. UnreadBytes() int // UnflushedBytes returns the number of pending/unflushed bytes. UnflushedBytes() int // Close (force) closes the connection. Close() error // contains filtered or unexported methods }
Conn wraps a single network connection and exposes common read/write methods.
type Pool ¶ added in v1.0.0
type Pool struct {
// contains filtered or unexported fields
}
Pool is a minimalist redis client connection pool
Example ¶
package main import ( "fmt" "github.com/markusleevip/taodb/client" "github.com/markusleevip/taodb/resp" ) func main() { pool, _ := client.New(nil) defer pool.Close() cn, _ := pool.Get() defer pool.Put(cn) // Build pipeline cn.WriteCmdString("PING") cn.WriteCmdString("ECHO", "HEllO") cn.WriteCmdString("GET", "key") cn.WriteCmdString("SET", "key", "value") cn.WriteCmdString("GET", "key") // Flush pipeline to socket if err := cn.Flush(); err != nil { cn.MarkFailed() panic(err) } // Consume responses for i := 0; i < 5; i++ { t, err := cn.PeekType() if err != nil { return } switch t { case resp.TypeInline: s, _ := cn.ReadInlineString() fmt.Println(s) case resp.TypeBulk: s, _ := cn.ReadBulkString() fmt.Println(s) case resp.TypeInt: n, _ := cn.ReadInt() fmt.Println(n) case resp.TypeNil: _ = cn.ReadNil() fmt.Println(nil) case resp.TypeError: err, _ := cn.ReadError() fmt.Println(err) default: panic("unexpected response type") } } }
Output: PONG HEllO ERR not found key: 'key' ok value
Click to show internal directories.
Click to hide internal directories.