README
¶
Redis client for Golang 
Supports:
- Redis 2.8 commands except QUIT, MONITOR, SLOWLOG and SYNC.
- Pub/sub.
- Transactions.
- Pipelining.
- Connection pool.
- TLS connections.
- Thread safety.
- Timeouts.
- Redis Sentinel.
API docs: http://godoc.org/gopkg.in/redis.v2. Examples: http://godoc.org/gopkg.in/redis.v2#pkg-examples.
Installation
Install:
go get gopkg.in/redis.v2
Look and feel
Some corner cases:
SORT list LIMIT 0 2 ASC
vals, err := client.Sort("list", redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result()
ZRANGEBYSCORE zset -inf +inf WITHSCORES LIMIT 0 2
vals, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{
Min: "-inf",
Max: "+inf",
Offset: 0,
Count: 2,
}).Result()
ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3 AGGREGATE SUM
vals, err := client.ZInterStore("out", redis.ZStore{Weights: []int64{2, 3}}, "zset1", "zset2").Result()
EVAL "return {KEYS[1],ARGV[1]}" 1 "key" "hello"
vals, err := client.Eval("return {KEYS[1],ARGV[1]}", []string{"key"}, []string{"hello"}).Result()
Documentation
¶
Overview ¶
Package redis implements a Redis client.
Example (CustomCommand) ¶
Output: "" redis: nil
Index ¶
- Variables
- type BitCount
- type BoolCmd
- type BoolSliceCmd
- type Client
- func (c *Client) Append(key, value string) *IntCmd
- func (c *Client) Auth(password string) *StatusCmd
- func (c *Client) BLPop(timeout int64, keys ...string) *StringSliceCmd
- func (c *Client) BRPop(timeout int64, keys ...string) *StringSliceCmd
- func (c *Client) BRPopLPush(source, destination string, timeout int64) *StringCmd
- func (c *Client) BgRewriteAOF() *StatusCmd
- func (c *Client) BgSave() *StatusCmd
- func (c *Client) BitCount(key string, bitCount *BitCount) *IntCmd
- func (c *Client) BitOpAnd(destKey string, keys ...string) *IntCmd
- func (c *Client) BitOpNot(destKey string, key string) *IntCmd
- func (c *Client) BitOpOr(destKey string, keys ...string) *IntCmd
- func (c *Client) BitOpXor(destKey string, keys ...string) *IntCmd
- func (c *Client) ClientKill(ipPort string) *StatusCmd
- func (c *Client) ClientList() *StringCmd
- func (c Client) Close() error
- func (c *Client) ConfigGet(parameter string) *SliceCmd
- func (c *Client) ConfigResetStat() *StatusCmd
- func (c *Client) ConfigSet(parameter, value string) *StatusCmd
- func (c *Client) DbSize() *IntCmd
- func (c *Client) DebugObject(key string) *StringCmd
- func (c *Client) Decr(key string) *IntCmd
- func (c *Client) DecrBy(key string, decrement int64) *IntCmd
- func (c *Client) Del(keys ...string) *IntCmd
- func (c *Client) Dump(key string) *StringCmd
- func (c *Client) Echo(message string) *StringCmd
- func (c *Client) Eval(script string, keys []string, args []string) *Cmd
- func (c *Client) EvalSha(sha1 string, keys []string, args []string) *Cmd
- func (c *Client) Exists(key string) *BoolCmd
- func (c *Client) Expire(key string, dur time.Duration) *BoolCmd
- func (c *Client) ExpireAt(key string, tm time.Time) *BoolCmd
- func (c *Client) FlushAll() *StatusCmd
- func (c *Client) FlushDb() *StatusCmd
- func (c *Client) Get(key string) *StringCmd
- func (c *Client) GetBit(key string, offset int64) *IntCmd
- func (c *Client) GetRange(key string, start, end int64) *StringCmd
- func (c *Client) GetSet(key, value string) *StringCmd
- func (c *Client) HDel(key string, fields ...string) *IntCmd
- func (c *Client) HExists(key, field string) *BoolCmd
- func (c *Client) HGet(key, field string) *StringCmd
- func (c *Client) HGetAll(key string) *StringSliceCmd
- func (c *Client) HGetAllMap(key string) *StringStringMapCmd
- func (c *Client) HIncrBy(key, field string, incr int64) *IntCmd
- func (c *Client) HIncrByFloat(key, field string, incr float64) *FloatCmd
- func (c *Client) HKeys(key string) *StringSliceCmd
- func (c *Client) HLen(key string) *IntCmd
- func (c *Client) HMGet(key string, fields ...string) *SliceCmd
- func (c *Client) HMSet(key, field, value string, pairs ...string) *StatusCmd
- func (c *Client) HScan(key string, cursor int64, match string, count int64) *ScanCmd
- func (c *Client) HSet(key, field, value string) *BoolCmd
- func (c *Client) HSetNX(key, field, value string) *BoolCmd
- func (c *Client) HVals(key string) *StringSliceCmd
- func (c *Client) Incr(key string) *IntCmd
- func (c *Client) IncrBy(key string, value int64) *IntCmd
- func (c *Client) IncrByFloat(key string, value float64) *FloatCmd
- func (c *Client) Info() *StringCmd
- func (c *Client) Keys(pattern string) *StringSliceCmd
- func (c *Client) LIndex(key string, index int64) *StringCmd
- func (c *Client) LInsert(key, op, pivot, value string) *IntCmd
- func (c *Client) LLen(key string) *IntCmd
- func (c *Client) LPop(key string) *StringCmd
- func (c *Client) LPush(key string, values ...string) *IntCmd
- func (c *Client) LPushX(key, value string) *IntCmd
- func (c *Client) LRange(key string, start, stop int64) *StringSliceCmd
- func (c *Client) LRem(key string, count int64, value string) *IntCmd
- func (c *Client) LSet(key string, index int64, value string) *StatusCmd
- func (c *Client) LTrim(key string, start, stop int64) *StatusCmd
- func (c *Client) LastSave() *IntCmd
- func (c *Client) MGet(keys ...string) *SliceCmd
- func (c *Client) MSet(pairs ...string) *StatusCmd
- func (c *Client) MSetNX(pairs ...string) *BoolCmd
- func (c *Client) Migrate(host, port, key string, db, timeout int64) *StatusCmd
- func (c *Client) Move(key string, db int64) *BoolCmd
- func (c *Client) Multi() *Multi
- func (c *Client) ObjectEncoding(keys ...string) *StringCmd
- func (c *Client) ObjectIdleTime(keys ...string) *DurationCmd
- func (c *Client) ObjectRefCount(keys ...string) *IntCmd
- func (c *Client) PExpire(key string, dur time.Duration) *BoolCmd
- func (c *Client) PExpireAt(key string, tm time.Time) *BoolCmd
- func (c *Client) PSetEx(key string, dur time.Duration, value string) *StatusCmd
- func (c *Client) PTTL(key string) *DurationCmd
- func (c *Client) Persist(key string) *BoolCmd
- func (c *Client) Ping() *StatusCmd
- func (c *Client) Pipeline() *Pipeline
- func (c *Client) Pipelined(f func(*Pipeline) error) ([]Cmder, error)
- func (c Client) Process(cmd Cmder)
- func (c *Client) PubSub() *PubSub
- func (c *Client) PubSubChannels(pattern string) *StringSliceCmd
- func (c *Client) PubSubNumPat() *IntCmd
- func (c *Client) PubSubNumSub(channels ...string) *SliceCmd
- func (c *Client) Publish(channel, message string) *IntCmd
- func (c *Client) Quit() *StatusCmd
- func (c *Client) RPop(key string) *StringCmd
- func (c *Client) RPopLPush(source, destination string) *StringCmd
- func (c *Client) RPush(key string, values ...string) *IntCmd
- func (c *Client) RPushX(key string, value string) *IntCmd
- func (c *Client) RandomKey() *StringCmd
- func (c *Client) Rename(key, newkey string) *StatusCmd
- func (c *Client) RenameNX(key, newkey string) *BoolCmd
- func (c *Client) Restore(key string, ttl int64, value string) *StatusCmd
- func (c *Client) SAdd(key string, members ...string) *IntCmd
- func (c *Client) SCard(key string) *IntCmd
- func (c *Client) SDiff(keys ...string) *StringSliceCmd
- func (c *Client) SDiffStore(destination string, keys ...string) *IntCmd
- func (c *Client) SInter(keys ...string) *StringSliceCmd
- func (c *Client) SInterStore(destination string, keys ...string) *IntCmd
- func (c *Client) SIsMember(key, member string) *BoolCmd
- func (c *Client) SMembers(key string) *StringSliceCmd
- func (c *Client) SMove(source, destination, member string) *BoolCmd
- func (c *Client) SPop(key string) *StringCmd
- func (c *Client) SRandMember(key string) *StringCmd
- func (c *Client) SRem(key string, members ...string) *IntCmd
- func (c *Client) SScan(key string, cursor int64, match string, count int64) *ScanCmd
- func (c *Client) SUnion(keys ...string) *StringSliceCmd
- func (c *Client) SUnionStore(destination string, keys ...string) *IntCmd
- func (c *Client) Save() *StatusCmd
- func (c *Client) Scan(cursor int64, match string, count int64) *ScanCmd
- func (c *Client) ScriptExists(scripts ...string) *BoolSliceCmd
- func (c *Client) ScriptFlush() *StatusCmd
- func (c *Client) ScriptKill() *StatusCmd
- func (c *Client) ScriptLoad(script string) *StringCmd
- func (c *Client) Select(index int64) *StatusCmd
- func (c *Client) Set(key, value string) *StatusCmd
- func (c *Client) SetBit(key string, offset int64, value int) *IntCmd
- func (c *Client) SetEx(key string, dur time.Duration, value string) *StatusCmd
- func (c *Client) SetNX(key, value string) *BoolCmd
- func (c *Client) SetRange(key string, offset int64, value string) *IntCmd
- func (c *Client) Shutdown() *StatusCmd
- func (c *Client) ShutdownNoSave() *StatusCmd
- func (c *Client) ShutdownSave() *StatusCmd
- func (c *Client) SlaveOf(host, port string) *StatusCmd
- func (c *Client) SlowLog()
- func (c *Client) Sort(key string, sort Sort) *StringSliceCmd
- func (c *Client) StrLen(key string) *IntCmd
- func (c *Client) Sync()
- func (c *Client) TTL(key string) *DurationCmd
- func (c *Client) Time() *StringSliceCmd
- func (c *Client) Type(key string) *StatusCmd
- func (c *Client) ZAdd(key string, members ...Z) *IntCmd
- func (c *Client) ZCard(key string) *IntCmd
- func (c *Client) ZCount(key, min, max string) *IntCmd
- func (c *Client) ZIncrBy(key string, increment float64, member string) *FloatCmd
- func (c *Client) ZInterStore(destination string, store ZStore, keys ...string) *IntCmd
- func (c *Client) ZRange(key string, start, stop int64) *StringSliceCmd
- func (c *Client) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd
- func (c *Client) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd
- func (c *Client) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd
- func (c *Client) ZRank(key, member string) *IntCmd
- func (c *Client) ZRem(key string, members ...string) *IntCmd
- func (c *Client) ZRemRangeByRank(key string, start, stop int64) *IntCmd
- func (c *Client) ZRemRangeByScore(key, min, max string) *IntCmd
- func (c *Client) ZRevRange(key, start, stop string) *StringSliceCmd
- func (c *Client) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd
- func (c *Client) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd
- func (c *Client) ZRevRangeWithScores(key, start, stop string) *ZSliceCmd
- func (c *Client) ZRevRank(key, member string) *IntCmd
- func (c *Client) ZScan(key string, cursor int64, match string, count int64) *ScanCmd
- func (c *Client) ZScore(key, member string) *FloatCmd
- func (c *Client) ZUnionStore(destination string, store ZStore, keys ...string) *IntCmd
- type Cmd
- type Cmder
- type DurationCmd
- type FailoverOptions
- type FloatCmd
- type IntCmd
- type Message
- type Multi
- type Options
- type PMessage
- type Pipeline
- type PubSub
- func (c PubSub) Close() error
- func (c *PubSub) PSubscribe(patterns ...string) error
- func (c *PubSub) PUnsubscribe(patterns ...string) error
- func (c PubSub) Process(cmd Cmder)
- func (c *PubSub) Receive() (interface{}, error)
- func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error)
- func (c *PubSub) Subscribe(channels ...string) error
- func (c *PubSub) Unsubscribe(channels ...string) error
- type ScanCmd
- type Script
- func (s *Script) Eval(c scripter, keys []string, args []string) *Cmd
- func (s *Script) EvalSha(c scripter, keys []string, args []string) *Cmd
- func (s *Script) Exists(c scripter) *BoolSliceCmd
- func (s *Script) Load(c scripter) *StringCmd
- func (s *Script) Run(c *Client, keys []string, args []string) *Cmd
- type SliceCmd
- type Sort
- type StatusCmd
- type StringCmd
- type StringSliceCmd
- type StringStringMapCmd
- type Subscription
- type Z
- type ZRangeByScore
- type ZSliceCmd
- type ZStore
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Nil = errorf("redis: nil")
Redis nil reply.
View Source
var TxFailedErr = errorf("redis: transaction failed")
Redis transaction failed.
Functions ¶
This section is empty.
Types ¶
type BoolSliceCmd ¶
type BoolSliceCmd struct {
// contains filtered or unexported fields
}
func NewBoolSliceCmd ¶
func NewBoolSliceCmd(args ...string) *BoolSliceCmd
func (*BoolSliceCmd) Result ¶
func (cmd *BoolSliceCmd) Result() ([]bool, error)
func (*BoolSliceCmd) String ¶
func (cmd *BoolSliceCmd) String() string
func (*BoolSliceCmd) Val ¶
func (cmd *BoolSliceCmd) Val() []bool
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Example ¶
Output: "" "redis: nil" true
func NewFailoverClient ¶
func NewFailoverClient(failoverOpt *FailoverOptions) *Client
Example ¶
Output: PONG <nil>
func (*Client) BRPopLPush ¶
func (*Client) BgRewriteAOF ¶
func (*Client) ClientKill ¶
func (*Client) ClientList ¶
func (Client) Close ¶
func (c Client) Close() error
Close closes the client, releasing any open resources.
func (*Client) ConfigResetStat ¶
func (*Client) DebugObject ¶
func (*Client) HGetAll ¶
func (c *Client) HGetAll(key string) *StringSliceCmd
func (*Client) HGetAllMap ¶
func (c *Client) HGetAllMap(key string) *StringStringMapCmd
func (*Client) HIncrByFloat ¶
func (*Client) HKeys ¶
func (c *Client) HKeys(key string) *StringSliceCmd
func (*Client) HVals ¶
func (c *Client) HVals(key string) *StringSliceCmd
func (*Client) Keys ¶
func (c *Client) Keys(pattern string) *StringSliceCmd
func (*Client) ObjectEncoding ¶
func (*Client) ObjectIdleTime ¶
func (c *Client) ObjectIdleTime(keys ...string) *DurationCmd
func (*Client) ObjectRefCount ¶
func (*Client) PTTL ¶
func (c *Client) PTTL(key string) *DurationCmd
func (*Client) PubSubChannels ¶
func (c *Client) PubSubChannels(pattern string) *StringSliceCmd
func (*Client) PubSubNumPat ¶
func (*Client) PubSubNumSub ¶
func (*Client) SDiff ¶
func (c *Client) SDiff(keys ...string) *StringSliceCmd
func (*Client) SInter ¶
func (c *Client) SInter(keys ...string) *StringSliceCmd
func (*Client) SInterStore ¶
func (*Client) SMembers ¶
func (c *Client) SMembers(key string) *StringSliceCmd
func (*Client) SRandMember ¶
func (*Client) SUnion ¶
func (c *Client) SUnion(keys ...string) *StringSliceCmd
func (*Client) SUnionStore ¶
func (*Client) ScriptExists ¶
func (c *Client) ScriptExists(scripts ...string) *BoolSliceCmd
func (*Client) ScriptFlush ¶
func (*Client) ScriptKill ¶
func (*Client) ScriptLoad ¶
func (*Client) ShutdownNoSave ¶
func (*Client) ShutdownSave ¶
func (*Client) TTL ¶
func (c *Client) TTL(key string) *DurationCmd
func (*Client) Time ¶
func (c *Client) Time() *StringSliceCmd
func (*Client) ZInterStore ¶
func (*Client) ZRangeByScore ¶
func (c *Client) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd
func (*Client) ZRangeByScoreWithScores ¶
func (c *Client) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd
func (*Client) ZRangeWithScores ¶
func (*Client) ZRemRangeByRank ¶
func (*Client) ZRemRangeByScore ¶
func (*Client) ZRevRange ¶
func (c *Client) ZRevRange(key, start, stop string) *StringSliceCmd
func (*Client) ZRevRangeByScore ¶
func (c *Client) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd
func (*Client) ZRevRangeByScoreWithScores ¶
func (c *Client) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd
func (*Client) ZRevRangeWithScores ¶
type DurationCmd ¶
type DurationCmd struct {
// contains filtered or unexported fields
}
func NewDurationCmd ¶
func NewDurationCmd(precision time.Duration, args ...string) *DurationCmd
func (*DurationCmd) String ¶
func (cmd *DurationCmd) String() string
func (*DurationCmd) Val ¶
func (cmd *DurationCmd) Val() time.Duration
type FailoverOptions ¶
type FloatCmd ¶
type FloatCmd struct {
// contains filtered or unexported fields
}
func NewFloatCmd ¶
type Multi ¶
type Multi struct {
*Client
}
Not thread-safe.
Example ¶
Output: [SET key 1: OK] <nil>
type Options ¶
type Options struct { Network string Addr string // Dialer creates new network connection and has priority over // Network and Addr options. Dialer func() (net.Conn, error) Password string DB int64 DialTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration PoolSize int IdleTimeout time.Duration }
type Pipeline ¶
type Pipeline struct { *Client // contains filtered or unexported fields }
Not thread-safe.
Example ¶
Output: [SET key1 hello1: OK GET key1: hello1] <nil> SET key1 hello1: OK GET key1: hello1
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
Not thread-safe.
Example ¶
Output: subscribe: mychannel <nil> Message<mychannel: hello> <nil>
func (PubSub) Close ¶
func (c PubSub) Close() error
Close closes the client, releasing any open resources.
func (*PubSub) PSubscribe ¶
func (*PubSub) PUnsubscribe ¶
func (*PubSub) ReceiveTimeout ¶
func (*PubSub) Unsubscribe ¶
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Example ¶
Output: 1 <nil> 0 <nil> GET keynx: foo
func (*Script) Exists ¶
func (s *Script) Exists(c scripter) *BoolSliceCmd
type SliceCmd ¶
type SliceCmd struct {
// contains filtered or unexported fields
}
func NewSliceCmd ¶
type StatusCmd ¶
type StatusCmd struct {
// contains filtered or unexported fields
}
func NewStatusCmd ¶
type StringCmd ¶
type StringCmd struct {
// contains filtered or unexported fields
}
func NewStringCmd ¶
type StringSliceCmd ¶
type StringSliceCmd struct {
// contains filtered or unexported fields
}
func NewStringSliceCmd ¶
func NewStringSliceCmd(args ...string) *StringSliceCmd
func (*StringSliceCmd) Result ¶
func (cmd *StringSliceCmd) Result() ([]string, error)
func (*StringSliceCmd) String ¶
func (cmd *StringSliceCmd) String() string
func (*StringSliceCmd) Val ¶
func (cmd *StringSliceCmd) Val() []string
type StringStringMapCmd ¶
type StringStringMapCmd struct {
// contains filtered or unexported fields
}
func NewStringStringMapCmd ¶
func NewStringStringMapCmd(args ...string) *StringStringMapCmd
func (*StringStringMapCmd) Result ¶
func (cmd *StringStringMapCmd) Result() (map[string]string, error)
func (*StringStringMapCmd) String ¶
func (cmd *StringStringMapCmd) String() string
func (*StringStringMapCmd) Val ¶
func (cmd *StringStringMapCmd) Val() map[string]string
type Subscription ¶
func (*Subscription) String ¶
func (m *Subscription) String() string
type ZRangeByScore ¶
type ZSliceCmd ¶
type ZSliceCmd struct {
// contains filtered or unexported fields
}
func NewZSliceCmd ¶
Click to show internal directories.
Click to hide internal directories.