Documentation ¶
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 Scan(src []interface{}, dest ...interface{}) ([]interface{}, error)
- func ScanSlice(src []interface{}, dest interface{}, fieldNames ...string) error
- func ScanStruct(src []interface{}, dest 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 Args
- type Conn
- func Dial(cx appengine.Context, network, address string) (Conn, error)
- func DialTimeout(cx appengine.Context, network, address string, ...) (Conn, error)
- func NewConn(netConn *socket.Conn, readTimeout, writeTimeout time.Duration) Conn
- func NewLoggingConn(conn Conn, logger *log.Logger, prefix string) Conn
- type Error
- type Message
- type PMessage
- type Pool
- type PubSubConn
- func (c PubSubConn) Close() error
- func (c PubSubConn) PSubscribe(channel ...interface{}) error
- func (c PubSubConn) PUnsubscribe(channel ...interface{}) error
- func (c PubSubConn) Receive() interface{}
- func (c PubSubConn) Subscribe(channel ...interface{}) error
- func (c PubSubConn) Unsubscribe(channel ...interface{}) error
- type Script
- type Subscription
Constants ¶
This section is empty.
Variables ¶
var ErrNil = errors.New("redigo: nil returned")
ErrNil indicates that a reply value is nil.
var ErrPoolExhausted = errors.New("redigo: connection pool exhausted")
ErrPoolExhausted is returned from a pool connection method (Do, Send, Receive, Flush, Err) when the maximum number of database connections in the pool has been reached.
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 Scan ¶
func Scan(src []interface{}, dest ...interface{}) ([]interface{}, error)
Scan copies from src to the values pointed at by dest.
The values pointed at by dest must be an integer, float, boolean, string, []byte, interface{} or slices of these types. Scan uses the standard strconv package to convert bulk strings to numeric and boolean types.
If a dest value is nil, then the corresponding src value is skipped.
If a src element is nil, then the corresponding dest value is not modified.
To enable easy use of Scan in a loop, Scan returns the slice of src following the copied values.
func ScanSlice ¶
ScanSlice scans src to the slice pointed to by dest. The elements the dest slice must be integer, float, boolean, string, struct or pointer to struct values.
Struct fields must be integer, float, boolean or string values. All struct fields are used unless a subset is specified using fieldNames.
func ScanStruct ¶
func ScanStruct(src []interface{}, dest interface{}) error
ScanStruct scans alternating names and values from src to a struct. The HGETALL and CONFIG GET commands return replies in this format.
ScanStruct uses exported field names to match values in the response. Use 'redis' field tag to override the name:
Field int `redis:"myName"`
Fields with the tag redis:"-" are ignored.
Integer, float, boolean, string and []byte fields are supported. Scan uses the standard strconv package to convert bulk string values to numeric and boolean types.
If a src element is nil, then the corresponding field is not modified.
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 Args ¶
type Args []interface{}
Args is a helper for constructing command arguments from structured values.
func (Args) AddFlat ¶
AddFlat returns the result of appending the flattened value of v to args.
Maps are flattened by appending the alternating keys and map values to args.
Slices are flattened by appending the slice elements to args.
Structs are flattened by appending the alternating names and values of exported fields to args. If v is a nil struct pointer, then nothing is appended. The 'redis' field tag overrides struct field names. See ScanStruct for more information on the use of the 'redis' field tag.
Other types are appended to args as is.
type Conn ¶
type Conn interface { // Close closes the connection. Close() error // Err returns a non-nil value if the connection is broken. The returned // value is either the first non-nil value returned from the underlying // network connection or a protocol parsing error. Applications should // close broken connections. Err() error // Do sends a command to the server and returns the received reply. Do(commandName string, args ...interface{}) (reply interface{}, err error) // Send writes the command to the client's output buffer. Send(commandName string, args ...interface{}) error // Flush flushes the output buffer to the Redis server. Flush() error // Receive receives a single reply from the Redis server Receive() (reply interface{}, err error) // Conn is the http.Conn that we can work with. SocketConn() *socket.Conn // LV3 AppEngine }
Conn represents a connection to a Redis server.
func DialTimeout ¶
func DialTimeout(cx appengine.Context, network, address string, connectTimeout, readTimeout, writeTimeout time.Duration) (Conn, error)
DialTimeout acts like Dial but takes timeouts for establishing the connection to the server, writing a command and reading a reply. lv3 AppEngine
type PMessage ¶
type PMessage struct { // The matched pattern. Pattern string // The originating channel. Channel string // The message data. Data []byte }
PMessage represents a pmessage notification.
type Pool ¶
type Pool struct { // Dial is an application supplied function for creating and configuring a // connection Dial func(cx appengine.Context) (Conn, error) // TestOnBorrow is an optional application supplied function for checking // the health of an idle connection before the connection is used again by // the application. Argument t is the time that the connection was returned // to the pool. If the function returns an error, then the connection is // closed. TestOnBorrow func(c Conn, t time.Time) error // Maximum number of idle connections in the pool. MaxIdle int // Maximum number of connections allocated by the pool at a given time. // When zero, there is no limit on the number of connections in the pool. MaxActive int // Close connections after remaining idle for this duration. If the value // is zero, then idle connections are not closed. Applications should set // the timeout to a value less than the server's timeout. IdleTimeout time.Duration // contains filtered or unexported fields }
Pool maintains a pool of connections. The application calls the Get method to get a connection from the pool and the connection's Close method to return the connection's resources to the pool.
The following example shows how to use a pool in a web application. The application creates a pool at application startup and makes it available to request handlers using a global variable.
func newPool(server, password string) *redis.Pool { return &redis.Pool{ MaxIdle: 3, IdleTimeout: 240 * time.Second, Dial: func (cx appengine.Context) (redis.Conn, error) { c, err := redis.Dial("tcp", server) if err != nil { return nil, err } if _, err := c.Do("AUTH", password); err != nil { c.Close() return nil, err } return c, err }, TestOnBorrow: func(c redis.Conn, t time.Time) error { _, err := c.Do("PING") return err }, } } var ( pool *redis.Pool redisServer = flag.String("redisServer", ":6379", "") redisPassword = flag.String("redisPassword", "", "") ) func main() { flag.Parse() pool = newPool(*redisServer, *redisPassword) ... }
A request handler gets a connection from the pool and closes the connection when the handler is done:
func serveHome(w http.ResponseWriter, r *http.Request) { conn := pool.Get(cx appengine.Context) defer conn.Close() .... }
func (*Pool) ActiveCount ¶
ActiveCount returns the number of active connections in the pool.
func (*Pool) Get ¶
Get gets a connection. The application must close the returned connection. This method always returns a valid connection so that applications can defer error handling to the first use of the connection. If there is an error getting an underlying connection, then the connection Err, Do, Send, Flush and Receive methods return that error.
type PubSubConn ¶
type PubSubConn struct {
Conn Conn
}
PubSubConn wraps a Conn with convenience methods for subscribers.
func (PubSubConn) PSubscribe ¶
func (c PubSubConn) PSubscribe(channel ...interface{}) error
PSubscribe subscribes the connection to the given patterns.
func (PubSubConn) PUnsubscribe ¶
func (c PubSubConn) PUnsubscribe(channel ...interface{}) error
PUnsubscribe unsubscribes the connection from the given patterns, or from all of them if none is given.
func (PubSubConn) Receive ¶
func (c PubSubConn) Receive() interface{}
Receive returns a pushed message as a Subscription, Message, PMessage or error. The return value is intended to be used directly in a type switch as illustrated in the PubSubConn example.
func (PubSubConn) Subscribe ¶
func (c PubSubConn) Subscribe(channel ...interface{}) error
Subscribe subscribes the connection to the specified channels.
func (PubSubConn) Unsubscribe ¶
func (c PubSubConn) Unsubscribe(channel ...interface{}) error
Unsubscribe unsubscribes the connection from the given channels, or from all of them if none is given.
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Script encapsulates the source, hash and key count for a Lua script. See http://redis.io/commands/eval for information on scripts in Redis.
func NewScript ¶
NewScript returns a new script object. If keyCount is greater than or equal to zero, then the count is automatically inserted in the EVAL command argument list. If keyCount is less than zero, then the application supplies the count as the first value in the keysAndArgs argument to the Do, Send and SendHash methods.
func (*Script) Do ¶
Do evaluates the script. Under the covers, Do optimistically evaluates the script using the EVALSHA command. If the command fails because the script is not loaded, then Do evaluates the script using the EVAL command (thus causing the script to load).
type Subscription ¶
type Subscription struct { // Kind is "subscribe", "unsubscribe", "psubscribe" or "punsubscribe" Kind string // The channel that was changed. Channel string // The current number of subscriptions for connection. Count int }
Subscription represents a subscribe or unsubscribe notification.