Documentation ¶
Overview ¶
Package redis implements a Redis client.
Example (CustomCommand) ¶
Get := func(client *redis.Client, key string) *redis.StringCmd { cmd := redis.NewStringCmd("GET", key) client.Process(cmd) return cmd } v, err := Get(client, "key_does_not_exist").Result() fmt.Printf("%q %s", v, err)
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 ¶
if err := client.Set("foo", "bar").Err(); err != nil { panic(err) } v, err := client.Get("hello").Result() fmt.Printf("%q %q %v", v, err, err == redis.Nil)
Output: "" "redis: nil" true
func NewFailoverClient ¶
func NewFailoverClient(failoverOpt *FailoverOptions) *Client
Example ¶
client := redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: "master", SentinelAddrs: []string{":26379"}, }) pong, err := client.Ping().Result() fmt.Println(pong, err)
Output: PONG <nil>
func NewTCPClient ¶
Deprecated. Use NewClient instead.
Example ¶
client := redis.NewTCPClient(&redis.Options{ Addr: "localhost:6379", Password: "", // no password set DB: 0, // use default DB }) pong, err := client.Ping().Result() fmt.Println(pong, err)
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) Incr ¶
Example ¶
if err := client.Incr("counter").Err(); err != nil { panic(err) } n, err := client.Get("counter").Int64() fmt.Println(n, err)
Output: 1 <nil>
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) Pipelined ¶
Example ¶
cmds, err := client.Pipelined(func(c *redis.Pipeline) error { c.Set("key1", "hello1") c.Get("key1") return nil }) fmt.Println(err) set := cmds[0].(*redis.StatusCmd) fmt.Println(set) get := cmds[1].(*redis.StringCmd) fmt.Println(get)
Output: <nil> SET key1 hello1: OK GET key1: hello1
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 ¶
incr := func(tx *redis.Multi) ([]redis.Cmder, error) { s, err := tx.Get("key").Result() if err != nil && err != redis.Nil { return nil, err } n, _ := strconv.ParseInt(s, 10, 64) return tx.Exec(func() error { tx.Set("key", strconv.FormatInt(n+1, 10)) return nil }) } client.Del("key") tx := client.Multi() defer tx.Close() watch := tx.Watch("key") _ = watch.Err() for { cmds, err := incr(tx) if err == redis.TxFailedErr { continue } else if err != nil { panic(err) } fmt.Println(cmds, err) break }
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 ¶
pipeline := client.Pipeline() set := pipeline.Set("key1", "hello1") get := pipeline.Get("key1") cmds, err := pipeline.Exec() fmt.Println(cmds, err) fmt.Println(set) fmt.Println(get)
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 ¶
pubsub := client.PubSub() defer pubsub.Close() err := pubsub.Subscribe("mychannel") _ = err msg, err := pubsub.Receive() fmt.Println(msg, err) pub := client.Publish("mychannel", "hello") _ = pub.Err() msg, err = pubsub.Receive() fmt.Println(msg, err)
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 ¶
setnx := redis.NewScript(` if redis.call("get", KEYS[1]) == false then redis.call("set", KEYS[1], ARGV[1]) return 1 end return 0 `) v1, err := setnx.Run(client, []string{"keynx"}, []string{"foo"}).Result() fmt.Println(v1.(int64), err) v2, err := setnx.Run(client, []string{"keynx"}, []string{"bar"}).Result() fmt.Println(v2.(int64), err) get := client.Get("keynx") fmt.Println(get)
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 ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
example
|
|
otel
Module
|
|
extra
|
|
rediscensus
Module
|
|
rediscmd
Module
|
|
redisotel
Module
|
Click to show internal directories.
Click to hide internal directories.