Documentation ¶
Overview ¶
Package redis provides a client for the redis cache server.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Append(key, value string) (int, error)
- func (c *Client) BLPop(timeout int, keys ...string) (k, v string, err error)
- func (c *Client) BRPop(timeout int, keys ...string) (k, v string, err error)
- func (c *Client) BRPopLPush(src, dst string, timeout int) (string, error)
- func (c *Client) BgRewriteAOF() (string, error)
- func (c *Client) BgSave() (string, error)
- func (c *Client) BitCount(key string, start, end int) (int, error)
- func (c *Client) BitOp(operation, destkey, key string, keys ...string) (int, error)
- func (c *Client) ClientKill(addr string) error
- func (c *Client) ClientList() ([]string, error)
- func (c *Client) ClientSetName(name string) error
- func (c *Client) Close()
- func (c *Client) ConfigGet(name string) (map[string]string, error)
- func (c *Client) ConfigResetStat() error
- func (c *Client) ConfigSet(name, value string) error
- func (c *Client) DBSize() (int, error)
- func (c *Client) DebugSegfault() error
- func (c *Client) Decr(key string) (int, error)
- func (c *Client) DecrBy(key string, decrement int) (int, error)
- func (c *Client) Del(keys ...string) (n int, err error)
- func (c *Client) Dump(key string) (string, error)
- func (c *Client) Echo(message string) (string, error)
- func (c *Client) Eval(script string, numkeys int, keys, args []string) (interface{}, error)
- func (c *Client) EvalSha(sha1 string, numkeys int, keys, args []string) (interface{}, error)
- func (c *Client) Exists(key string) (bool, error)
- func (c *Client) Expire(key string, seconds int) (bool, error)
- func (c *Client) ExpireAt(key string, timestamp int) (bool, error)
- func (c *Client) FlushAll() error
- func (c *Client) FlushDB() error
- func (c *Client) Get(key string) (string, error)
- func (c *Client) GetBit(key string, offset int) (int, error)
- func (c *Client) GetRange(key string, start, end int) (string, error)
- func (c *Client) GetSet(key, value string) (string, error)
- func (c *Client) HDel(key, field string) (err error)
- func (c *Client) HGet(key, member string) (string, error)
- func (c *Client) HGetAll(key string) (map[string]string, error)
- func (c *Client) HIncrBy(key string, field string, increment int) (int, error)
- func (c *Client) HMGet(key string, field ...string) ([]string, error)
- func (c *Client) HMSet(key string, items map[string]string) (err error)
- func (c *Client) HScan(hash string, cursor string, options ...interface{}) (string, map[string]string, error)
- func (c *Client) HSet(key, field, value string) (err error)
- func (c *Client) Incr(key string) (int, error)
- func (c *Client) IncrBy(key string, increment int) (int, error)
- func (c *Client) Keys(pattern string) ([]string, error)
- func (c *Client) LIndex(key string, index int) (string, error)
- func (c *Client) LLen(key string) (int, error)
- func (c *Client) LPop(key string) (string, error)
- func (c *Client) LPush(key string, values ...string) (int, error)
- func (c *Client) LRange(key string, begin, end int) ([]string, error)
- func (c *Client) LRem(key string, count int, value string) (int, error)
- func (c *Client) LTrim(key string, begin, end int) (err error)
- func (c *Client) MGet(keys ...string) ([]string, error)
- func (c *Client) MSet(items map[string]string) error
- func (c *Client) PFAdd(key string, vs ...interface{}) (int, error)
- func (c *Client) PFCount(keys ...string) (int, error)
- func (c *Client) PFMerge(keys ...string) (err error)
- func (c *Client) Ping() error
- func (c *Client) Publish(channel, message string) error
- func (c *Client) RPop(key string) (string, error)
- func (c *Client) RPush(key string, values ...string) (int, error)
- func (c *Client) SAdd(key string, vs ...interface{}) (int, error)
- func (c *Client) SCard(key string) (int, error)
- func (c *Client) SIsMember(key string, vs ...interface{}) (int, error)
- func (c *Client) SMembers(key string) ([]string, error)
- func (c *Client) SMove(source string, destination string, member string) (int, error)
- func (c *Client) SRandMember(key string, count int) ([]string, error)
- func (c *Client) SRem(key string, vs ...interface{}) (int, error)
- func (c *Client) SScan(set string, cursor string, options ...interface{}) (string, []string, error)
- func (c *Client) Scan(cursor string, options ...interface{}) (string, []string, error)
- func (c *Client) ScriptLoad(script string) (string, error)
- func (c *Client) Set(key, value string) (err error)
- func (c *Client) SetBit(key string, offset, value int) (int, error)
- func (c *Client) SetEx(key string, seconds int, value string) (err error)
- func (c *Client) SetNx(key, value string) (int, error)
- func (c *Client) SetTimeout(max time.Duration)
- func (c *Client) Subscribe(channel string, m chan<- PubSubMessage, stop <-chan bool) error
- func (c *Client) TTL(key string) (int, error)
- func (c *Client) ZAdd(key string, vs ...interface{}) (int, error)
- func (c *Client) ZCard(key string) (int, error)
- func (c *Client) ZCount(key string, min int, max int) (int, error)
- func (c *Client) ZIncrBy(key string, increment int, member string) (string, error)
- func (c *Client) ZRange(key string, start int, stop int, withscores bool) ([]string, error)
- func (c *Client) ZRem(key string, vs ...interface{}) (int, error)
- func (c *Client) ZRemRangeByScore(key string, start interface{}, stop interface{}) (int, error)
- func (c *Client) ZRevRange(key string, start int, stop int, withscores bool) ([]string, error)
- func (c *Client) ZScan(zset string, cursor string, options ...interface{}) (string, map[string]string, error)
- func (c *Client) ZScore(key string, member string) (string, error)
- type ConnectTimeoutError
- type PubSubMessage
- type ServerInfo
- type ServerList
- type ServerSelector
Constants ¶
const DefaultTimeout = time.Second
DefaultTimeout is the default socket read/write timeout.
Variables ¶
var ( // MaxIdleConnsPerAddr is the maximum number of connections // (per server address) idling in the pool. // // Only update this value before creating or using the client. MaxIdleConnsPerAddr = 10 // ErrNoServers is returned when no servers are configured or available. ErrNoServers = errors.New("redis: no servers configured or available") // ErrServerError means that a server error occurred. ErrServerError = errors.New("redis: server error") // ErrTimedOut is returned when a Read or Write operation times out ErrTimedOut = errors.New("redis: timed out") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a redis client. It is safe for use by multiple concurrent goroutines.
func New ¶
New returns a redis client using the provided server(s) with equal weight. If a server is listed multiple times, it gets a proportional amount of weight.
New supports ip:port or /unix/path, and optional *db* and *passwd* arguments. Example:
rc := redis.New("ip:port db=N passwd=foobared") rc := redis.New("/tmp/redis.sock db=N passwd=foobared")
New panics if the configured servers point to names that cannot be resolved to an address, or unix socket path.
func NewFromSelector ¶
func NewFromSelector(ss ServerSelector) *Client
NewFromSelector returns a new Client using the provided ServerSelector.
func (*Client) Append ¶
Append implements http://redis.io/commands/append.
func (*Client) BLPop ¶
BLPop implements http://redis.io/commands/blpop. Cannot be sharded.
If timeout is 0, DefaultTimeout is used.
func (*Client) BRPop ¶
BRPop implements http://redis.io/commands/brpop. Cannot be sharded.
If timeout is 0, DefaultTimeout is used.
func (*Client) BRPopLPush ¶
BRPopLPush implements http://redis.io/commands/brpoplpush. Cannot be sharded.
If timeout is 0, DefaultTimeout is used.
func (*Client) BgRewriteAOF ¶
BgRewriteAOF implements http://redis.io/commands/bgrewriteaof. Cannot be sharded.
func (*Client) BgSave ¶
BgSave implements http://redis.io/commands/bgsave. Cannot be sharded.
func (*Client) BitCount ¶
BitCount implements http://redis.io/commands/bitcount. Start and end are ignored if start is a negative number.
func (*Client) BitOp ¶
BitOp implements http://redis.io/commands/bitop. Cannot be sharded.
func (*Client) ClientKill ¶
ClientKill implements http://redis.io/commands/client-kill. Cannot be sharded.
func (*Client) ClientList ¶
ClientList implements http://redis.io/commands/client-list. Cannot be sharded.
func (*Client) ClientSetName ¶
ClientSetName implements http://redis.io/commands/client-setname. Cannot be sharded.
This driver creates connections on demand, thus naming them is pointless.
func (*Client) ConfigGet ¶
ConfigGet implements http://redis.io/commands/config-get. Cannot be sharded.
func (*Client) ConfigResetStat ¶
ConfigResetStat implements http://redis.io/commands/config-resetstat. Cannot be sharded.
func (*Client) ConfigSet ¶
ConfigSet implements http://redis.io/commands/config-set. Cannot be sharded.
func (*Client) DBSize ¶
DBSize implements http://redis.io/commands/dbsize. Cannot be sharded.
func (*Client) DebugSegfault ¶
DebugSegfault implements http://redis.io/commands/debug-segfault. Cannot be sharded.
func (*Client) Decr ¶
Decr implements http://redis.io/commands/decr.
func (*Client) DecrBy ¶
DecrBy implements http://redis.io/commands/decrby.
func (*Client) Del ¶
Del implements http://redis.io/commands/del. Del issues a plain DEL command to redis if the client is connected to a single server. On sharded connections, it issues one DEL command per key, in the server selected for each given key.
func (*Client) Dump ¶
Dump implements http://redis.io/commands/dump.
func (*Client) Echo ¶
Echo implements http://redis.io/commands/echo.
func (*Client) Eval ¶
Eval implemenets http://redis.io/commands/eval. Cannot be sharded.
func (*Client) EvalSha ¶
EvalSha implements http://redis.io/commands/evalsha. Cannot be sharded.
func (*Client) Exists ¶
Exists implements http://redis.io/commands/exists.
func (*Client) Expire ¶
Expire implements http://redis.io/commands/expire. Expire returns true if a timeout was set for the given key, or false when key does not exist or the timeout could not be set.
func (*Client) ExpireAt ¶
ExpireAt implements http://redis.io/commands/expireat. ExpireAt behaves like Expire.
func (*Client) FlushAll ¶
FlushAll implements http://redis.io/commands/flushall. Cannot be sharded.
func (*Client) FlushDB ¶
FlushDB implements http://redis.io/commands/flushall. Cannot be sharded.
func (*Client) Get ¶
Get implements http://redis.io/commands/get.
func (*Client) GetBit ¶
GetBit implements http://redis.io/commands/getbit.
func (*Client) GetRange ¶
GetRange implements http://redis.io/commands/getrange.
func (*Client) GetSet ¶
GetSet implements http://redis.io/commands/getset.
func (*Client) HDel ¶
HDel implements http://redis.io/commands/hdel.
func (*Client) HGet ¶
HGet implements http://redis.io/commands/hget.
func (*Client) HGetAll ¶
HGetAll implements http://redis.io/commands/hgetall.
func (*Client) HIncrBy ¶
HIncrBy implements http://redis.io/commands/hincrby.
func (*Client) HMGet ¶
HMGet implements http://redis.io/commands/hmget.
func (*Client) HMSet ¶
HMSet implements http://redis.io/commands/hmset.
func (*Client) HScan ¶
func (c *Client) HScan(hash string, cursor string, options ...interface{}) (string, map[string]string, error)
HScan implements http://redis.io/commands/hscan.
func (*Client) HSet ¶
HSet implements http://redis.io/commands/hset.
func (*Client) Incr ¶
Incr implements http://redis.io/commands/incr.
func (*Client) IncrBy ¶
IncrBy implements http://redis.io/commands/incrby.
func (*Client) Keys ¶
Keys implement http://redis.io/commands/keys. Cannot be sharded.
func (*Client) LIndex ¶
LIndex implements http://redis.io/commands/lindex.
func (*Client) LLen ¶
LLen implements http://redis.io/commands/llen.
func (*Client) LPop ¶
LPop implements http://redis.io/commands/lpop.
func (*Client) LPush ¶
LPush implements http://redis.io/commands/lpush.
func (*Client) LRange ¶
LRange implements http://redis.io/commands/lrange.
func (*Client) LRem ¶
LRem implements http://redis.io/commands/lrem.
func (*Client) LTrim ¶
LTrim implements http://redis.io/commands/ltrim.
func (*Client) MGet ¶
MGet implements http://redis.io/commands/mget. Cannot be sharded.
TODO: support sharded connections.
func (*Client) MSet ¶
MSet implements http://redis.io/commands/mset. Cannot be sharded.
TODO: support sharded connections.
func (*Client) PFAdd ¶
PFAdd implements http://redis.io/commands/pfadd.
func (*Client) PFCount ¶
PFCount implements http://redis.io/commands/pfcount.
func (*Client) PFMerge ¶
PFMerge implements http://redis.io/commands/pfmerge.
func (*Client) Ping ¶
Ping implements http://redis.io/commands/ping. Cannot be sharded.
func (*Client) Publish ¶
Publish implements http://redis.io/commands/publish.
func (*Client) RPop ¶
RPop implements http://redis.io/commands/rpop.
func (*Client) RPush ¶
RPush implements http://redis.io/commands/rpush.
func (*Client) SAdd ¶
SAdd implements http://redis.io/commands/sadd.
func (*Client) SCard ¶
SCard implements http://redis.io/commands/scard.
func (*Client) SIsMember ¶
SIsMember implements http://redis.io/commands/sismember.
func (*Client) SMembers ¶
SMembers implements http://redis.io/commands/smembers.
func (*Client) SMove ¶
SMove implements http://redis.io/commands/smove.
func (*Client) SRandMember ¶
SRandMember implements http://redis.io/commands/srandmember.
func (*Client) SRem ¶
SRem implements http://redis.io/commands/srem.
func (*Client) SScan ¶
SScan implements http://redis.io/commands/sscan.
func (*Client) Scan ¶
Scan implements http://redis.io/commands/scan.
func (*Client) ScriptLoad ¶
ScriptLoad implements http://redis.io/commands/script-load. Cannot be sharded.
func (*Client) Set ¶
Set implements http://redis.io/commands/set.
func (*Client) SetBit ¶
SetBit implements http://redis.io/commands/setbit.
func (*Client) SetEx ¶
SetEx implements http://redis.io/commands/setex.
func (*Client) SetNx ¶
SetNx implements http://redis.io/commands/setnx.
func (*Client) SetTimeout ¶
SetTimeout sets the client timeout for read/write operations.
func (*Client) Subscribe ¶
func (c *Client) Subscribe(channel string, m chan<- PubSubMessage, stop <-chan bool) error
Subscribe implements http://redis.io/commands/subscribe.
func (*Client) TTL ¶
TTL implements http://redis.io/commands/ttl.
func (*Client) ZAdd ¶
ZAdd implements http://redis.io/commands/zadd.
func (*Client) ZCard ¶
ZCard implements http://redis.io/commands/zcard.
func (*Client) ZCount ¶
ZCount implements http://redis.io/commands/zcount.
func (*Client) ZIncrBy ¶
ZIncrBy implements http://redis.io/commands/zincrby.
func (*Client) ZRange ¶
ZRange implements http://redis.io/commands/zrange.
func (*Client) ZRem ¶
ZRem implements http://redis.io/commands/zrem.
func (*Client) ZRemRangeByScore ¶
ZRemRangeByScore implements http://redis.io/commands/zremrangebyscore.
func (*Client) ZRevRange ¶
ZRevRange implements http://redis.io/commands/zrevrange.
type ConnectTimeoutError ¶
ConnectTimeoutError is the error type used when it takes too long to connect to the desired host. This level of detail can generally be ignored.
func (*ConnectTimeoutError) Error ¶
func (cte *ConnectTimeoutError) Error() string
type PubSubMessage ¶
A PubSubMessage carries redis pub/sub messages for clients that are subscribed to a topic. See Subscribe for details.
type ServerInfo ¶
ServerInfo stores parsed the server information.
type ServerList ¶
type ServerList struct {
// contains filtered or unexported fields
}
ServerList is a simple ServerSelector. Its zero value is usable.
func (*ServerList) PickServer ¶
func (ss *ServerList) PickServer(key string) (srv ServerInfo, err error)
PickServer implements the ServerSelector interface.
func (*ServerList) SetServers ¶
func (ss *ServerList) SetServers(servers ...string) error
SetServers changes a ServerList's set of servers at runtime and is threadsafe.
Each server is given equal weight. A server is given more weight if it's listed multiple times.
SetServers returns an error if any of the server names fail to resolve. No attempt is made to connect to the server. If any error is returned, no changes are made to the ServerList.
func (*ServerList) Sharding ¶
func (ss *ServerList) Sharding() bool
Sharding implements the ServerSelector interface.
type ServerSelector ¶
type ServerSelector interface { // PickServer returns the server address that a given item // should be shared onto, or the first listed server if an // empty key is given. PickServer(key string) (ServerInfo, error) // Sharding indicates that the client can connect to multiple servers. Sharding() bool }
ServerSelector is the interface that selects a redis server as a function of the item's key.
All ServerSelector implementations must be threadsafe.