package redis
import "github.com/go-redis/redis"
Package redis implements a Redis client.
Code:
Output: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
}
"" redis: nil
Index ¶
- Variables
- type BitCount
- type BoolCmd
- func NewBoolCmd(args ...string) *BoolCmd
- func (cmd BoolCmd) Err() error
- func (cmd *BoolCmd) Result() (bool, error)
- func (cmd *BoolCmd) String() string
- func (cmd *BoolCmd) Val() bool
- type BoolSliceCmd
- func NewBoolSliceCmd(args ...string) *BoolSliceCmd
- func (cmd BoolSliceCmd) Err() error
- func (cmd *BoolSliceCmd) Result() ([]bool, error)
- func (cmd *BoolSliceCmd) String() string
- func (cmd *BoolSliceCmd) Val() []bool
- type Client
- func NewClient(clOpt *Options) *Client
- func NewFailoverClient(failoverOpt *FailoverOptions) *Client
- func NewTCPClient(opt *Options) *Client
- func NewUnixClient(opt *Options) *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
- func NewCmd(args ...string) *Cmd
- func (cmd Cmd) Err() error
- func (cmd *Cmd) Result() (interface{}, error)
- func (cmd *Cmd) String() string
- func (cmd *Cmd) Val() interface{}
- type Cmder
- type DurationCmd
- func NewDurationCmd(precision time.Duration, args ...string) *DurationCmd
- func (cmd DurationCmd) Err() error
- func (cmd *DurationCmd) Result() (time.Duration, error)
- func (cmd *DurationCmd) String() string
- func (cmd *DurationCmd) Val() time.Duration
- type FailoverOptions
- type FloatCmd
- func NewFloatCmd(args ...string) *FloatCmd
- func (cmd FloatCmd) Err() error
- func (cmd *FloatCmd) String() string
- func (cmd *FloatCmd) Val() float64
- type IntCmd
- func NewIntCmd(args ...string) *IntCmd
- func (cmd IntCmd) Err() error
- func (cmd *IntCmd) Result() (int64, error)
- func (cmd *IntCmd) String() string
- func (cmd *IntCmd) Val() int64
- type Message
- type Multi
- func (c *Multi) Close() error
- func (c *Multi) Discard() error
- func (c *Multi) Exec(f func() error) ([]Cmder, error)
- func (c Multi) Process(cmd Cmder)
- func (c *Multi) Unwatch(keys ...string) *StatusCmd
- func (c *Multi) Watch(keys ...string) *StatusCmd
- type Options
- type PMessage
- type Pipeline
- func (c *Pipeline) Close() error
- func (c *Pipeline) Discard() error
- func (c *Pipeline) Exec() ([]Cmder, error)
- func (c Pipeline) Process(cmd Cmder)
- 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
- func NewScanCmd(args ...string) *ScanCmd
- func (cmd ScanCmd) Err() error
- func (cmd *ScanCmd) Result() (int64, []string, error)
- func (cmd *ScanCmd) String() string
- func (cmd *ScanCmd) Val() (int64, []string)
- type Script
- func NewScript(src string) *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
- func NewSliceCmd(args ...string) *SliceCmd
- func (cmd SliceCmd) Err() error
- func (cmd *SliceCmd) Result() ([]interface{}, error)
- func (cmd *SliceCmd) String() string
- func (cmd *SliceCmd) Val() []interface{}
- type Sort
- type StatusCmd
- func NewStatusCmd(args ...string) *StatusCmd
- func (cmd StatusCmd) Err() error
- func (cmd *StatusCmd) Result() (string, error)
- func (cmd *StatusCmd) String() string
- func (cmd *StatusCmd) Val() string
- type StringCmd
- func NewStringCmd(args ...string) *StringCmd
- func (cmd StringCmd) Err() error
- func (cmd *StringCmd) Float64() (float64, error)
- func (cmd *StringCmd) Int64() (int64, error)
- func (cmd *StringCmd) Result() (string, error)
- func (cmd *StringCmd) String() string
- func (cmd *StringCmd) Uint64() (uint64, error)
- func (cmd *StringCmd) Val() string
- type StringSliceCmd
- func NewStringSliceCmd(args ...string) *StringSliceCmd
- func (cmd StringSliceCmd) Err() error
- func (cmd *StringSliceCmd) Result() ([]string, error)
- func (cmd *StringSliceCmd) String() string
- func (cmd *StringSliceCmd) Val() []string
- type StringStringMapCmd
- func NewStringStringMapCmd(args ...string) *StringStringMapCmd
- func (cmd StringStringMapCmd) Err() error
- func (cmd *StringStringMapCmd) Result() (map[string]string, error)
- func (cmd *StringStringMapCmd) String() string
- func (cmd *StringStringMapCmd) Val() map[string]string
- type Subscription
- type Z
- type ZRangeByScore
- type ZSliceCmd
- func NewZSliceCmd(args ...string) *ZSliceCmd
- func (cmd ZSliceCmd) Err() error
- func (cmd *ZSliceCmd) Result() ([]Z, error)
- func (cmd *ZSliceCmd) String() string
- func (cmd *ZSliceCmd) Val() []Z
- type ZStore
Examples ¶
- package (CustomCommand)
- Client
- Client.Incr
- Client.Pipelined
- Multi
- NewFailoverClient
- NewTCPClient
- Pipeline
- PubSub
- Script
Variables ¶
var Nil = errorf("redis: nil")
Redis nil reply.
var TxFailedErr = errorf("redis: transaction failed")
Redis transaction failed.
Types ¶
type BitCount ¶
type BitCount struct { Start, End int64 }
type BoolCmd ¶
type BoolCmd struct {
// contains filtered or unexported fields
}
func NewBoolCmd ¶
func (BoolCmd) Err ¶
func (cmd BoolCmd) Err() error
func (*BoolCmd) Result ¶
func (*BoolCmd) String ¶
func (*BoolCmd) Val ¶
type BoolSliceCmd ¶
type BoolSliceCmd struct {
// contains filtered or unexported fields
}
func NewBoolSliceCmd ¶
func NewBoolSliceCmd(args ...string) *BoolSliceCmd
func (BoolSliceCmd) Err ¶
func (cmd BoolSliceCmd) Err() error
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¶
Code:
{
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
}
Output:
"" "redis: nil" true
func NewClient ¶
func NewFailoverClient ¶
func NewFailoverClient(failoverOpt *FailoverOptions) *Client
Example¶
Code:
{
client := redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "master",
SentinelAddrs: []string{":26379"},
})
pong, err := client.Ping().Result()
fmt.Println(pong, err)
// Output: PONG <nil>
}
Output:
PONG <nil>
func NewTCPClient ¶
Deprecated. Use NewClient instead.
Code:
Output: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>
}
PONG <nil>
func NewUnixClient ¶
Deprecated. Use NewClient instead.
func (*Client) Append ¶
func (*Client) Auth ¶
func (*Client) BLPop ¶
func (c *Client) BLPop(timeout int64, keys ...string) *StringSliceCmd
func (*Client) BRPop ¶
func (c *Client) BRPop(timeout int64, keys ...string) *StringSliceCmd
func (*Client) BRPopLPush ¶
func (*Client) BgRewriteAOF ¶
func (*Client) BgSave ¶
func (*Client) BitCount ¶
func (*Client) BitOpAnd ¶
func (*Client) BitOpNot ¶
func (*Client) BitOpOr ¶
func (*Client) BitOpXor ¶
func (*Client) ClientKill ¶
func (*Client) ClientList ¶
func (Client) Close ¶
func (c Client) Close() error
Close closes the client, releasing any open resources.
func (*Client) ConfigGet ¶
func (*Client) ConfigResetStat ¶
func (*Client) ConfigSet ¶
func (*Client) DbSize ¶
func (*Client) DebugObject ¶
func (*Client) Decr ¶
func (*Client) DecrBy ¶
func (*Client) Del ¶
func (*Client) Dump ¶
func (*Client) Echo ¶
func (*Client) Eval ¶
func (*Client) EvalSha ¶
func (*Client) Exists ¶
func (*Client) Expire ¶
func (*Client) ExpireAt ¶
func (*Client) FlushAll ¶
func (*Client) FlushDb ¶
func (*Client) Get ¶
func (*Client) GetBit ¶
func (*Client) GetRange ¶
func (*Client) GetSet ¶
func (*Client) HDel ¶
func (*Client) HExists ¶
func (*Client) HGet ¶
func (*Client) HGetAll ¶
func (c *Client) HGetAll(key string) *StringSliceCmd
func (*Client) HGetAllMap ¶
func (c *Client) HGetAllMap(key string) *StringStringMapCmd
func (*Client) HIncrBy ¶
func (*Client) HIncrByFloat ¶
func (*Client) HKeys ¶
func (c *Client) HKeys(key string) *StringSliceCmd
func (*Client) HLen ¶
func (*Client) HMGet ¶
func (*Client) HMSet ¶
func (*Client) HScan ¶
func (*Client) HSet ¶
func (*Client) HSetNX ¶
func (*Client) HVals ¶
func (c *Client) HVals(key string) *StringSliceCmd
func (*Client) Incr ¶
Example¶
Code:
{
if err := client.Incr("counter").Err(); err != nil {
panic(err)
}
n, err := client.Get("counter").Int64()
fmt.Println(n, err)
// Output: 1 <nil>
}
Output:
1 <nil>
func (*Client) IncrBy ¶
func (*Client) IncrByFloat ¶
func (*Client) Info ¶
func (*Client) Keys ¶
func (c *Client) Keys(pattern string) *StringSliceCmd
func (*Client) LIndex ¶
func (*Client) LInsert ¶
func (*Client) LLen ¶
func (*Client) LPop ¶
func (*Client) LPush ¶
func (*Client) LPushX ¶
func (*Client) LRange ¶
func (c *Client) LRange(key string, start, stop int64) *StringSliceCmd
func (*Client) LRem ¶
func (*Client) LSet ¶
func (*Client) LTrim ¶
func (*Client) LastSave ¶
func (*Client) MGet ¶
func (*Client) MSet ¶
func (*Client) MSetNX ¶
func (*Client) Migrate ¶
func (*Client) Move ¶
func (*Client) Multi ¶
func (*Client) ObjectEncoding ¶
func (*Client) ObjectIdleTime ¶
func (c *Client) ObjectIdleTime(keys ...string) *DurationCmd
func (*Client) ObjectRefCount ¶
func (*Client) PExpire ¶
func (*Client) PExpireAt ¶
func (*Client) PSetEx ¶
func (*Client) PTTL ¶
func (c *Client) PTTL(key string) *DurationCmd
func (*Client) Persist ¶
func (*Client) Ping ¶
func (*Client) Pipeline ¶
func (*Client) Pipelined ¶
Example¶
Code:
{
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
}
Output:
<nil> SET key1 hello1: OK GET key1: hello1
func (Client) Process ¶
func (c Client) Process(cmd Cmder)
func (*Client) PubSub ¶
func (*Client) PubSubChannels ¶
func (c *Client) PubSubChannels(pattern string) *StringSliceCmd
func (*Client) PubSubNumPat ¶
func (*Client) PubSubNumSub ¶
func (*Client) Publish ¶
func (*Client) Quit ¶
func (*Client) RPop ¶
func (*Client) RPopLPush ¶
func (*Client) RPush ¶
func (*Client) RPushX ¶
func (*Client) RandomKey ¶
func (*Client) Rename ¶
func (*Client) RenameNX ¶
func (*Client) Restore ¶
func (*Client) SAdd ¶
func (*Client) SCard ¶
func (*Client) SDiff ¶
func (c *Client) SDiff(keys ...string) *StringSliceCmd
func (*Client) SDiffStore ¶
func (*Client) SInter ¶
func (c *Client) SInter(keys ...string) *StringSliceCmd
func (*Client) SInterStore ¶
func (*Client) SIsMember ¶
func (*Client) SMembers ¶
func (c *Client) SMembers(key string) *StringSliceCmd
func (*Client) SMove ¶
func (*Client) SPop ¶
func (*Client) SRandMember ¶
func (*Client) SRem ¶
func (*Client) SScan ¶
func (*Client) SUnion ¶
func (c *Client) SUnion(keys ...string) *StringSliceCmd
func (*Client) SUnionStore ¶
func (*Client) Save ¶
func (*Client) Scan ¶
func (*Client) ScriptExists ¶
func (c *Client) ScriptExists(scripts ...string) *BoolSliceCmd
func (*Client) ScriptFlush ¶
func (*Client) ScriptKill ¶
func (*Client) ScriptLoad ¶
func (*Client) Select ¶
func (*Client) Set ¶
func (*Client) SetBit ¶
func (*Client) SetEx ¶
func (*Client) SetNX ¶
func (*Client) SetRange ¶
func (*Client) Shutdown ¶
func (*Client) ShutdownNoSave ¶
func (*Client) ShutdownSave ¶
func (*Client) SlaveOf ¶
func (*Client) SlowLog ¶
func (c *Client) SlowLog()
func (*Client) Sort ¶
func (c *Client) Sort(key string, sort Sort) *StringSliceCmd
func (*Client) StrLen ¶
func (*Client) Sync ¶
func (c *Client) Sync()
func (*Client) TTL ¶
func (c *Client) TTL(key string) *DurationCmd
func (*Client) Time ¶
func (c *Client) Time() *StringSliceCmd
func (*Client) Type ¶
func (*Client) ZAdd ¶
func (*Client) ZCard ¶
func (*Client) ZCount ¶
func (*Client) ZIncrBy ¶
func (*Client) ZInterStore ¶
func (*Client) ZRange ¶
func (c *Client) ZRange(key string, start, stop int64) *StringSliceCmd
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) ZRank ¶
func (*Client) ZRem ¶
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 ¶
func (*Client) ZRevRank ¶
func (*Client) ZScan ¶
func (*Client) ZScore ¶
func (*Client) ZUnionStore ¶
type Cmd ¶
type Cmd struct {
// contains filtered or unexported fields
}
func NewCmd ¶
func (Cmd) Err ¶
func (cmd Cmd) Err() error
func (*Cmd) Result ¶
func (*Cmd) String ¶
func (*Cmd) Val ¶
func (cmd *Cmd) Val() interface{}
type Cmder ¶
type DurationCmd ¶
type DurationCmd struct {
// contains filtered or unexported fields
}
func NewDurationCmd ¶
func NewDurationCmd(precision time.Duration, args ...string) *DurationCmd
func (DurationCmd) Err ¶
func (cmd DurationCmd) Err() error
func (*DurationCmd) Result ¶
func (cmd *DurationCmd) Result() (time.Duration, error)
func (*DurationCmd) String ¶
func (cmd *DurationCmd) String() string
func (*DurationCmd) Val ¶
func (cmd *DurationCmd) Val() time.Duration
type FailoverOptions ¶
type FailoverOptions struct { MasterName string SentinelAddrs []string Password string DB int64 PoolSize int DialTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration }
type FloatCmd ¶
type FloatCmd struct {
// contains filtered or unexported fields
}
func NewFloatCmd ¶
func (FloatCmd) Err ¶
func (cmd FloatCmd) Err() error
func (*FloatCmd) String ¶
func (*FloatCmd) Val ¶
type IntCmd ¶
type IntCmd struct {
// contains filtered or unexported fields
}
func NewIntCmd ¶
func (IntCmd) Err ¶
func (cmd IntCmd) Err() error
func (*IntCmd) Result ¶
func (*IntCmd) String ¶
func (*IntCmd) Val ¶
type Message ¶
func (*Message) String ¶
type Multi ¶
type Multi struct { *Client }
Not thread-safe.
Code:
Output: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>
}
[SET key 1: OK] <nil>
func (*Multi) Close ¶
func (*Multi) Discard ¶
func (*Multi) Exec ¶
Exec always returns list of commands. If transaction fails TxFailedErr is returned. Otherwise Exec returns error of the first failed command or nil.
func (Multi) Process ¶
func (c Multi) Process(cmd Cmder)
func (*Multi) Unwatch ¶
func (*Multi) Watch ¶
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 PMessage ¶
func (*PMessage) String ¶
type Pipeline ¶
type Pipeline struct { *Client // contains filtered or unexported fields }
Not thread-safe.
Code:
Output: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
}
[SET key1 hello1: OK GET key1: hello1] <nil>
SET key1 hello1: OK
GET key1: hello1
func (*Pipeline) Close ¶
func (*Pipeline) Discard ¶
func (*Pipeline) Exec ¶
Exec always returns list of commands and error of the first failed command if any.
func (Pipeline) Process ¶
func (c Pipeline) Process(cmd Cmder)
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
Not thread-safe.
Code:
Output: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>
}
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) Process ¶
func (c PubSub) Process(cmd Cmder)
func (*PubSub) Receive ¶
func (*PubSub) ReceiveTimeout ¶
func (*PubSub) Subscribe ¶
func (*PubSub) Unsubscribe ¶
type ScanCmd ¶
type ScanCmd struct {
// contains filtered or unexported fields
}
func NewScanCmd ¶
func (ScanCmd) Err ¶
func (cmd ScanCmd) Err() error
func (*ScanCmd) Result ¶
func (*ScanCmd) String ¶
func (*ScanCmd) Val ¶
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Example¶
Code:
{
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
}
Output:
1 <nil> 0 <nil> GET keynx: foo
func NewScript ¶
func (*Script) Eval ¶
func (*Script) EvalSha ¶
func (*Script) Exists ¶
func (s *Script) Exists(c scripter) *BoolSliceCmd
func (*Script) Load ¶
func (*Script) Run ¶
type SliceCmd ¶
type SliceCmd struct {
// contains filtered or unexported fields
}
func NewSliceCmd ¶
func (SliceCmd) Err ¶
func (cmd SliceCmd) Err() error
func (*SliceCmd) Result ¶
func (*SliceCmd) String ¶
func (*SliceCmd) Val ¶
func (cmd *SliceCmd) Val() []interface{}
type Sort ¶
type Sort struct { By string Offset, Count float64 Get []string Order string IsAlpha bool Store string }
type StatusCmd ¶
type StatusCmd struct {
// contains filtered or unexported fields
}
func NewStatusCmd ¶
func (StatusCmd) Err ¶
func (cmd StatusCmd) Err() error
func (*StatusCmd) Result ¶
func (*StatusCmd) String ¶
func (*StatusCmd) Val ¶
type StringCmd ¶
type StringCmd struct {
// contains filtered or unexported fields
}
func NewStringCmd ¶
func (StringCmd) Err ¶
func (cmd StringCmd) Err() error
func (*StringCmd) Float64 ¶
func (*StringCmd) Int64 ¶
func (*StringCmd) Result ¶
func (*StringCmd) String ¶
func (*StringCmd) Uint64 ¶
func (*StringCmd) Val ¶
type StringSliceCmd ¶
type StringSliceCmd struct {
// contains filtered or unexported fields
}
func NewStringSliceCmd ¶
func NewStringSliceCmd(args ...string) *StringSliceCmd
func (StringSliceCmd) Err ¶
func (cmd StringSliceCmd) Err() error
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) Err ¶
func (cmd StringStringMapCmd) Err() error
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 Z ¶
type ZRangeByScore ¶
type ZSliceCmd ¶
type ZSliceCmd struct {
// contains filtered or unexported fields
}
func NewZSliceCmd ¶
func (ZSliceCmd) Err ¶
func (cmd ZSliceCmd) Err() error
func (*ZSliceCmd) Result ¶
func (*ZSliceCmd) String ¶
func (*ZSliceCmd) Val ¶
type ZStore ¶
Source Files ¶
command.go commands.go doc.go error.go multi.go parser.go pipeline.go pool.go pubsub.go rate_limit.go redis.go script.go sentinel.go
- Version
- v2.3.1+incompatible
- Published
- Nov 13, 2014
- Platform
- windows/amd64
- Imports
- 14 packages
- Last checked
- 1 week ago –
Tools for package owners.