Documentation ¶
Overview ¶
Package redis implement a pure redis cluster client, meaning it doesn't support any cluster commands.
Create a new cluster client with specified options:
cluster, err := redis.NewCluster( &redis.Options{ StartNodes: []string{"127.0.0.1:7000", "127.0.0.1:7001", "127.0.0.1:7002"}, ConnTimeout: 50 * time.Millisecond, ReadTimeout: 50 * time.Millisecond, WriteTimeout: 50 * time.Millisecond, KeepAlive: 16, AliveTime: 60 * time.Second, })
For basic usage:
cluster.Do("SET", "foo", "bar") cluster.Do("INCR", "mycount", 1) cluster.Do("LPUSH", "mylist", "foo", "bar") cluster.Do("HMSET", "myhash", "f1", "foo", "f2", "bar")
Use convert help functions to convert replies to int, float, string, etc:
reply, err := Int(cluster.Do("INCR", "mycount", 1)) reply, err := String(cluster.Do("GET", "foo")) reply, err := Strings(cluster.Do("LRANGE", "mylist", 0, -1)) reply, err := StringMap(cluster.Do("HGETALL", "myhash"))
Use batch interface to pack multiple commands for pipelining:
batch := cluster.NewBatch() batch.Put("LPUSH", "country_list", "France") batch.Put("LPUSH", "country_list", "Italy") batch.Put("LPUSH", "country_list", "Germany") batch.Put("INCRBY", "countries", 3) batch.Put("LRANGE", "country_list", 0, -1)
Index ¶
- Constants
- 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 Inform(cluster *Cluster, node *redisNode)
- func Int(reply interface{}, err error) (int, error)
- func Int64(reply interface{}, err error) (int64, error)
- func Ints(reply interface{}, err error) ([]int, error)
- func Scan(src []interface{}, dst ...interface{}) ([]interface{}, error)
- func String(reply interface{}, err error) (string, error)
- func StringMap(result interface{}, err error) (map[string]string, error)
- func Strings(reply interface{}, err error) ([]string, error)
- func Values(reply interface{}, err error) ([]interface{}, error)
- type Batch
- type Cluster
- func (cluster *Cluster) Close()
- func (cluster *Cluster) Do(cmd string, args ...interface{}) (interface{}, error)
- func (cluster *Cluster) IsSlaveOperate() bool
- func (cluster *Cluster) NewBatch(numSeed uint64) *Batch
- func (cluster *Cluster) RunBatch(bat *Batch) ([]interface{}, error)
- func (cluster *Cluster) SlaveDo(cmd string, args ...interface{}) (interface{}, error)
- func (cluster *Cluster) Update(node *redisNode) error
- func (cluster *Cluster) UpdateSlotsByRandomMasterNode()
- func (cluster *Cluster) UpdateSlotsInfoByRandomNode(node *redisNode)
- type Options
Constants ¶
const ( MASTER_NODE = 1 SLAVE_NODE = 2 )
Variables ¶
var Cluster_Down_Error = errors.New("CLUSTERDOWN")
var ErrNil = errors.New("nil reply")
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 Ints ¶
Ints is a helper that converts an array command reply to a []int. If err is not equal to nil, then Ints returns nil, err.
func Scan ¶
func Scan(src []interface{}, dst ...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 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 StringMap ¶
StringMap is a helper that converts an array of strings (alternating key, value) into a map[string]string. The HGETALL and CONFIG GET commands return replies in this format. Requires an even number of values in result.
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. Nil array items are converted to "" in the output slice. Strings returns an error if an array item is not a bulk string or nil.
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
func (*Batch) GetIsSlaveOperate ¶
func (*Batch) SetIsSlaveOperate ¶
func (batch *Batch) SetIsSlaveOperate()
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
func NewCluster ¶
func (*Cluster) IsSlaveOperate ¶
func (*Cluster) UpdateSlotsByRandomMasterNode ¶
func (cluster *Cluster) UpdateSlotsByRandomMasterNode()
func (*Cluster) UpdateSlotsInfoByRandomNode ¶
func (cluster *Cluster) UpdateSlotsInfoByRandomNode(node *redisNode)