Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type FloatCmd
- type IntCmd
- type IntSliceCmd
- type Pair
- type Pipeliner
- type Redis
- func (r *Redis) Close() (err error)
- func (r *Redis) Del(ctx context.Context, keys ...string) (num int64, err error)
- func (r *Redis) Exists(ctx context.Context, key string) (value bool, err error)
- func (r *Redis) Expire(ctx context.Context, key string, seconds int) (err error)
- func (r *Redis) ForceUnLock(ctx context.Context, key string) error
- func (r *Redis) Get(ctx context.Context, key string) (value string, err error)
- func (r *Redis) HDel(ctx context.Context, key string, fields ...string) (value int64, err error)
- func (r *Redis) HExists(ctx context.Context, key string, field string) (value bool, err error)
- func (r *Redis) HGet(ctx context.Context, key string, field string) (value string, err error)
- func (r *Redis) HGetAll(ctx context.Context, key string) (value map[string]string, err error)
- func (r *Redis) HIncrBy(ctx context.Context, key string, field string, increment int64) (value int64, err error)
- func (r *Redis) HKeys(ctx context.Context, key string) (value []string, err error)
- func (r *Redis) HLen(ctx context.Context, key string) (value int64, err error)
- func (r *Redis) HMGet(ctx context.Context, key string, fields ...string) (value []string, err error)
- func (r *Redis) HMSet(ctx context.Context, key string, kvs map[string]string) (err error)
- func (r *Redis) HSet(ctx context.Context, key string, field string, value string) (err error)
- func (r *Redis) IncrBy(ctx context.Context, key string, increment int64) (value int64, err error)
- func (r *Redis) LIndex(ctx context.Context, key string, index int64) (value string, err error)
- func (r *Redis) LLen(ctx context.Context, key string) (value int64, err error)
- func (r *Redis) LPop(ctx context.Context, key string) (value string, err error)
- func (r *Redis) LPopN(ctx context.Context, key string, count int) (value []string, err error)
- func (r *Redis) LPush(ctx context.Context, key string, values ...interface{}) (value int64, err error)
- func (r *Redis) LRange(ctx context.Context, key string, start int64, stop int64) (value []string, err error)
- func (r *Redis) LRem(ctx context.Context, key string, count int64, val string) (value int64, err error)
- func (r *Redis) Lock(ctx context.Context, key string, expireTime ...int) (locked bool, lockValue string, err error)
- func (r *Redis) MGet(ctx context.Context, keys ...string) (value []string, err error)
- func (r *Redis) MSet(ctx context.Context, kvs map[string]string) (err error)
- func (r *Redis) Ping(ctx context.Context) (alive bool)
- func (r *Redis) Pipelined(ctx context.Context, fn func(pipe Pipeliner) error) (value []redis.Cmder, err error)
- func (r *Redis) RPop(ctx context.Context, key string) (value string, err error)
- func (r *Redis) RPush(ctx context.Context, key string, values ...interface{}) (value int64, err error)
- func (r *Redis) SAdd(ctx context.Context, key string, members ...interface{}) (value int64, err error)
- func (r *Redis) SCard(ctx context.Context, key string) (value int64, err error)
- func (r *Redis) SDiff(ctx context.Context, keys ...string) (value []string, err error)
- func (r *Redis) SDiffStore(ctx context.Context, destination string, keys ...string) (value int64, err error)
- func (r *Redis) SIntersect(ctx context.Context, keys ...string) (value []string, err error)
- func (r *Redis) SIntersectStore(ctx context.Context, destination string, keys ...string) (value int64, err error)
- func (r *Redis) SIsMember(ctx context.Context, key string, member interface{}) (value bool, err error)
- func (r *Redis) SMembers(ctx context.Context, key string) (value []string, err error)
- func (r *Redis) SPop(ctx context.Context, key string) (value string, err error)
- func (r *Redis) SPopN(ctx context.Context, key string, count int64) (value []string, err error)
- func (r *Redis) SRandMember(ctx context.Context, key string) (value string, err error)
- func (r *Redis) SRandMemberN(ctx context.Context, key string, count int64) (value []string, err error)
- func (r *Redis) SRem(ctx context.Context, key string, members ...interface{}) (value int64, err error)
- func (r *Redis) SUnion(ctx context.Context, keys ...string) (value []string, err error)
- func (r *Redis) SUnionStore(ctx context.Context, destination string, keys ...string) (value int64, err error)
- func (r *Redis) Set(ctx context.Context, key string, value string) (err error)
- func (r *Redis) SetEx(ctx context.Context, key string, value string, seconds int) (err error)
- func (r *Redis) SetNxEx(ctx context.Context, key string, value string, milliseconds int) (locked bool, err error)
- func (r *Redis) TTL(ctx context.Context, key string) (value time.Duration, err error)
- func (r *Redis) TxPipelined(ctx context.Context, fn func(pipe Pipeliner) error) (value []redis.Cmder, err error)
- func (r *Redis) UnLock(ctx context.Context, key, lockValue string) error
- func (r *Redis) ZAdd(ctx context.Context, key string, pais ...*Pair) (value int64, err error)
- func (r *Redis) ZCard(ctx context.Context, key string) (value int64, err error)
- func (r *Redis) ZCount(ctx context.Context, key string, min int64, max int64) (value int64, err error)
- func (r *Redis) ZIncrBy(ctx context.Context, key string, member string, increment int64) (value int64, err error)
- func (r *Redis) ZPopMaxN(ctx context.Context, key string, count ...int64) (value []*Pair, err error)
- func (r *Redis) ZPopMin(ctx context.Context, key string, count ...int64) (value []*Pair, err error)
- func (r *Redis) ZRange(ctx context.Context, key string, start int64, stop int64) (value []string, err error)
- func (r *Redis) ZRangeByScore(ctx context.Context, key string, min int64, max int64) (value []string, err error)
- func (r *Redis) ZRangeWithScores(ctx context.Context, key string, start int64, stop int64) (value []*Pair, err error)
- func (r *Redis) ZRank(ctx context.Context, key string, member string) (value int64, err error)
- func (r *Redis) ZRem(ctx context.Context, key string, members ...interface{}) (value int64, err error)
- func (r *Redis) ZRemRangeByRank(ctx context.Context, key string, start int64, stop int64) (value int64, err error)
- func (r *Redis) ZRemRangeByScore(ctx context.Context, key string, min int64, max int64) (value int64, err error)
- func (r *Redis) ZRevRange(ctx context.Context, key string, start int64, stop int64) (value []string, err error)
- func (r *Redis) ZRevRangeByScore(ctx context.Context, key string, zrb *ZRangeBy) (value []string, err error)
- func (r *Redis) ZRevRangeByScoreWithScores(ctx context.Context, key string, zrb *ZRangeBy) (value []*Pair, err error)
- func (r *Redis) ZRevRangeWithScores(ctx context.Context, key string, start int64, stop int64) (value []*Pair, err error)
- func (r *Redis) ZRevRank(ctx context.Context, key string, member string) (value int64, err error)
- func (r *Redis) ZScore(ctx context.Context, key string, member string) (value int64, err error)
- type StringCmd
- type StringSliceCmd
- type StringStringMapCmd
- type Z
- type ZRangeBy
- type ZStore
Constants ¶
const (
// Nil is an alias of redis.Nil
Nil = redis.Nil
)
Variables ¶
var (
ErrUnLockGet = errors.New("lock has already unlocked or expired")
)
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // DBName metric name DBName string // DBIndex redis db index DBIndex int // Addr redis address Addr []string // Password auth password Password string // DeployMode deploy mode DeployMode string // MasterName master name for sentinel mode MasterName string // MinIdleConns min idle connections MinIdleConns int // DialTimeout dial redis timeout DialTimeout time.Duration // ReadTimeout read time out ReadTimeout time.Duration // WriteTimeout write time out WriteTimeout time.Duration // SlowOpTimeout slow query threshold SlowOpTimeout time.Duration // contains filtered or unexported fields }
Config redis configs
type FloatCmd ¶ added in v1.3.0
type FloatCmd = redis.FloatCmd
FloatCmd is an alias of redis.FloatCmd
type IntSliceCmd ¶ added in v1.3.0
type IntSliceCmd = redis.IntSliceCmd
IntSliceCmd is an alias of redis.IntSliceCmd
type Pipeliner ¶ added in v1.3.0
type Pipeliner = redis.Pipeliner
Pipeliner is an alias of redis.Pipeliner
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis redis instance
func New ¶
New returns a redis instance according deploy mode. There are three deploy mode. node: standalone sentinel: master-slave failover sentinel cluster: cluster mode
func (*Redis) Del ¶ added in v1.3.0
Del removes the specified keys, a key is ignored if it does not exist
func (*Redis) ForceUnLock ¶
ForceUnLock force unlock resource
func (*Redis) Get ¶ added in v1.3.0
Get get the value of key. If the key does not exist the special value nil is returned
func (*Redis) HExists ¶ added in v1.3.0
HExists returns if field is an existing field in the hash stored at key
func (*Redis) HGet ¶ added in v1.3.0
HGet returns the value associated with field in the hash stored at key
func (*Redis) HGetAll ¶ added in v1.3.0
HGetAll returns all fields and values of the hash stored at key
func (*Redis) HIncrBy ¶ added in v1.3.0
func (r *Redis) HIncrBy(ctx context.Context, key string, field string, increment int64) (value int64, err error)
HIncrBy increments the number stored at field in the hash stored at key by increment
func (*Redis) HLen ¶ added in v1.3.0
HLen returns the number of fields contained in the hash stored at key
func (*Redis) HMGet ¶ added in v1.3.0
func (r *Redis) HMGet(ctx context.Context, key string, fields ...string) (value []string, err error)
HMGet returns the values associated with the specified fields in the hash stored at key
func (*Redis) HMSet ¶ added in v1.3.0
HMSet sets the specified fields to their respective values in the hash stored at key
func (*Redis) LIndex ¶ added in v1.3.0
LIndex returns the element at index index in the list stored at key
func (*Redis) LPop ¶ added in v1.3.0
LPop removes and returns the first elements of the list stored at key
func (*Redis) LPopN ¶ added in v1.3.2
LPopN removes and returns the N elements of the list stored at key
func (*Redis) LPush ¶ added in v1.3.0
func (r *Redis) LPush(ctx context.Context, key string, values ...interface{}) (value int64, err error)
LPush insert all the specified values at the head of the list stored at key
func (*Redis) LRange ¶ added in v1.3.0
func (r *Redis) LRange(ctx context.Context, key string, start int64, stop int64) (value []string, err error)
LRange returns the specified elements of the list stored at key
func (*Redis) LRem ¶ added in v1.3.0
func (r *Redis) LRem(ctx context.Context, key string, count int64, val string) (value int64, err error)
LRem removes the first count occurrences of elements equal to element from the list stored at key
func (*Redis) Lock ¶
func (r *Redis) Lock(ctx context.Context, key string, expireTime ...int) (locked bool, lockValue string, err error)
Lock lock resource default lock 1000ms and retry 3 times, retry delay is 15ms
func (*Redis) Ping ¶ added in v0.2.0
Ping ping is used to test if a connection is still alive, or to measure latency
func (*Redis) Pipelined ¶ added in v1.3.0
func (r *Redis) Pipelined(ctx context.Context, fn func(pipe Pipeliner) error) (value []redis.Cmder, err error)
Pipelined batch execute commands
func (*Redis) RPop ¶ added in v1.3.0
RPop removes and returns the last elements of the list stored at key
func (*Redis) RPush ¶ added in v1.3.0
func (r *Redis) RPush(ctx context.Context, key string, values ...interface{}) (value int64, err error)
RPush insert all the specified values at the tail of the list stored at key
func (*Redis) SAdd ¶ added in v1.3.0
func (r *Redis) SAdd(ctx context.Context, key string, members ...interface{}) (value int64, err error)
SAdd add the specified members to the set stored at key
func (*Redis) SCard ¶ added in v1.3.0
SCard returns the set cardinality (number of elements) of the set stored at key
func (*Redis) SDiff ¶ added in v1.3.0
SDiff returns the members of the set resulting from the difference between the first set and all the successive sets
func (*Redis) SDiffStore ¶ added in v1.3.0
func (r *Redis) SDiffStore(ctx context.Context, destination string, keys ...string) (value int64, err error)
SDiffStore this command is equal to SDIFF but instead of returning the resulting set, it is stored in destination
func (*Redis) SIntersect ¶ added in v1.3.0
SIntersect returns the members of the set resulting from the intersection of all the given sets
func (*Redis) SIntersectStore ¶ added in v1.3.0
func (r *Redis) SIntersectStore(ctx context.Context, destination string, keys ...string) (value int64, err error)
SIntersectStore this command is equal to SIntersect but instead of returning the resulting set, it is stored in destination
func (*Redis) SIsMember ¶ added in v1.3.0
func (r *Redis) SIsMember(ctx context.Context, key string, member interface{}) (value bool, err error)
SIsMember returns if member is a member of the set stored at key
func (*Redis) SMembers ¶ added in v1.3.0
SMembers returns all the members of the set value stored at key
func (*Redis) SPop ¶ added in v1.3.0
SPop removes and returns one random members from the set value store at key
func (*Redis) SPopN ¶ added in v1.3.0
SPopN removes and returns count random members from the set value store at key
func (*Redis) SRandMember ¶ added in v1.3.0
SRandMember return a random element from the set value stored at key
func (*Redis) SRandMemberN ¶ added in v1.3.0
func (r *Redis) SRandMemberN(ctx context.Context, key string, count int64) (value []string, err error)
SRandMemberN return a count element from the set value stored at key
func (*Redis) SRem ¶ added in v1.3.0
func (r *Redis) SRem(ctx context.Context, key string, members ...interface{}) (value int64, err error)
SRem remove the specified members from the set stored at key
func (*Redis) SUnion ¶ added in v1.3.0
SUnion returns the members of the set resulting from the union of all the given sets
func (*Redis) SUnionStore ¶ added in v1.3.0
func (r *Redis) SUnionStore(ctx context.Context, destination string, keys ...string) (value int64, err error)
SUnionStore this command is equal to SUnion but instead of returning the resulting set, it is stored in destination
func (*Redis) SetEx ¶ added in v1.3.0
SetEx set key to hold the string value and set key to timeout after a given number of seconds
func (*Redis) SetNxEx ¶ added in v1.3.0
func (r *Redis) SetNxEx(ctx context.Context, key string, value string, milliseconds int) (locked bool, err error)
SetNxEx set key to hold string value if key does not exist and set key to timeout after a given number of milliseconds
func (*Redis) TTL ¶ added in v1.3.0
TTL returns the remaining time to live of a key that has a timeout
func (*Redis) TxPipelined ¶ added in v1.3.0
func (r *Redis) TxPipelined(ctx context.Context, fn func(pipe Pipeliner) error) (value []redis.Cmder, err error)
TxPipelined acts like Pipeline, but wraps queued commands with MULTI/EXEC
func (*Redis) ZAdd ¶ added in v1.3.0
ZAdd adds all the specified members with the specified scores to the sorted set
func (*Redis) ZCount ¶ added in v1.3.0
func (r *Redis) ZCount(ctx context.Context, key string, min int64, max int64) (value int64, err error)
ZCount returns the number of elements in the sorted set with a score between min and max
func (*Redis) ZIncrBy ¶ added in v1.3.0
func (r *Redis) ZIncrBy(ctx context.Context, key string, member string, increment int64) (value int64, err error)
ZIncrBy increments the score of member in the sorted set stored at key by increment
func (*Redis) ZPopMaxN ¶ added in v1.3.0
func (r *Redis) ZPopMaxN(ctx context.Context, key string, count ...int64) (value []*Pair, err error)
ZPopMax removes and returns up to count members with the highest scores in the sorted set the default value for count is 1, specifying a count greater than len(set) will not produce an error
func (*Redis) ZPopMin ¶ added in v1.3.0
ZPopMin removes and returns up to count members with the lowest scores in the sorted set the default value for count is 1, specifying a count greater than len(set) will not produce an error
func (*Redis) ZRange ¶ added in v1.3.0
func (r *Redis) ZRange(ctx context.Context, key string, start int64, stop int64) (value []string, err error)
ZRange returns the specified range of elements in the sorted set with the scores ordered from high to low
func (*Redis) ZRangeByScore ¶ added in v1.3.0
func (r *Redis) ZRangeByScore(ctx context.Context, key string, min int64, max int64) (value []string, err error)
ZRangeByScore returns all the elements in the sorted set with a score between min and max
func (*Redis) ZRangeWithScores ¶ added in v1.3.0
func (r *Redis) ZRangeWithScores(ctx context.Context, key string, start int64, stop int64) (value []*Pair, err error)
ZRangeWithScores this command is similar to ZRange but with score option
func (*Redis) ZRank ¶ added in v1.3.0
ZRank returns the rank of member in the sorted set stored, with the scores ordered from low to high The rank (or index) is 0-based, which means that the member with the lowest score has rank 0
func (*Redis) ZRem ¶ added in v1.3.0
func (r *Redis) ZRem(ctx context.Context, key string, members ...interface{}) (value int64, err error)
ZRem removes the specified members from the sorted set stored. Non existing members are ignored
func (*Redis) ZRemRangeByRank ¶ added in v1.3.0
func (r *Redis) ZRemRangeByRank(ctx context.Context, key string, start int64, stop int64) (value int64, err error)
ZRemRangeByRank removes all elements in the sorted set stored with rank between start and stop
func (*Redis) ZRemRangeByScore ¶ added in v1.3.0
func (r *Redis) ZRemRangeByScore(ctx context.Context, key string, min int64, max int64) (value int64, err error)
ZRemRangeByScore removes all elements in the sorted set stored with a score between min and max (inclusive)
func (*Redis) ZRevRange ¶ added in v1.3.0
func (r *Redis) ZRevRange(ctx context.Context, key string, start int64, stop int64) (value []string, err error)
ZRevRange returns the specified range of elements in the sorted set stored with the scores ordered from high to low
func (*Redis) ZRevRangeByScore ¶ added in v1.3.0
func (r *Redis) ZRevRangeByScore(ctx context.Context, key string, zrb *ZRangeBy) (value []string, err error)
ZRevRangeByScore returns all the elements in the sorted set at key with a score between max and min including elements with score equal to max or min
func (*Redis) ZRevRangeByScoreWithScores ¶ added in v1.3.0
func (r *Redis) ZRevRangeByScoreWithScores(ctx context.Context, key string, zrb *ZRangeBy) (value []*Pair, err error)
ZRevRangeByScoreWithScores this command is similar to ZRevRangeByScore but with score option
func (*Redis) ZRevRangeWithScores ¶ added in v1.3.0
func (r *Redis) ZRevRangeWithScores(ctx context.Context, key string, start int64, stop int64) (value []*Pair, err error)
ZRevRangeWithScores this command is similar to ZRevRange but with score option
type StringCmd ¶ added in v1.3.0
type StringCmd = redis.StringCmd
StringCmd is an alias of redis.StringCmd
type StringSliceCmd ¶ added in v1.3.0
type StringSliceCmd = redis.StringSliceCmd
StringSliceCmd is an alias of redis.StringSliceCmd
type StringStringMapCmd ¶ added in v1.3.0
type StringStringMapCmd = redis.StringStringMapCmd
StringStringMapCmd is an alias of redis.StringStringMapCmd