Documentation ¶
Index ¶
- Constants
- func InitClient(name string, cli *redis.Client)
- func InitClusterClient(name string, cli *redis.ClusterClient)
- type Mutex
- func (m *Mutex) Lock(ctx context.Context, key string, second int) (bool, error)
- func (m *Mutex) LockRenewal(ctx context.Context, key string) (lock bool, val string, err error)
- func (m *Mutex) UnLock(ctx context.Context, key string) (bool, error)
- func (m *Mutex) UnLockRenewal(ctx context.Context, key, val string) (bool, error)
- type RedisClient
- func (r *RedisClient) Client() *redis.Client
- func (r *RedisClient) ClusterClient() *redis.ClusterClient
- func (r *RedisClient) Decr(ctx context.Context, key string) (int64, error)
- func (r *RedisClient) DecrBy(ctx context.Context, key string, val int64) (int64, error)
- func (r *RedisClient) Del(ctx context.Context, keys ...string) (int64, error)
- func (r *RedisClient) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
- func (r *RedisClient) EvalSha(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
- func (r *RedisClient) Exists(ctx context.Context, keys ...string) (int64, error)
- func (r *RedisClient) Expire(ctx context.Context, key string, expiration time.Duration) (bool, error)
- func (r *RedisClient) GeoAdd(ctx context.Context, key string, geoLocation ...*redis.GeoLocation) (int64, error)
- func (r *RedisClient) GeoDist(ctx context.Context, key string, member1 string, member2 string, unit string) (float64, error)
- func (r *RedisClient) GeoHash(ctx context.Context, key string, members ...string) ([]string, error)
- func (r *RedisClient) GeoPos(ctx context.Context, key string, members ...string) ([]*redis.GeoPos, error)
- func (r *RedisClient) GeoRadius(ctx context.Context, key string, longitude float64, latitude float64, ...) ([]redis.GeoLocation, error)
- func (r *RedisClient) GeoRadiusByMember(ctx context.Context, key string, member string, query *redis.GeoRadiusQuery) ([]redis.GeoLocation, error)
- func (r *RedisClient) GeoRadiusByMemberStore(ctx context.Context, key string, member string, query *redis.GeoRadiusQuery) (int64, error)
- func (r *RedisClient) GeoRadiusStore(ctx context.Context, key string, longitude float64, latitude float64, ...) (int64, error)
- func (r *RedisClient) Get(ctx context.Context, key string) (string, error)
- func (r *RedisClient) GetEx(ctx context.Context, key string, expiration time.Duration) (string, error)
- func (r *RedisClient) HDel(ctx context.Context, key string, field ...string) (int64, error)
- func (r *RedisClient) HExists(ctx context.Context, key string, field string) (bool, error)
- func (r *RedisClient) HGetAll(ctx context.Context, key string) (map[string]string, error)
- func (r *RedisClient) HGetOne(ctx context.Context, key string, field string) (string, error)
- func (r *RedisClient) HIncrBy(ctx context.Context, key string, field string, incr int64) (int64, error)
- func (r *RedisClient) HIncrByFloat(ctx context.Context, key string, field string, incr float64) (float64, error)
- func (r *RedisClient) HKeys(ctx context.Context, key string) ([]string, error)
- func (r *RedisClient) HLen(ctx context.Context, key string) (int64, error)
- func (r *RedisClient) HMGet(ctx context.Context, key string, field ...string) ([]interface{}, error)
- func (r *RedisClient) HSet(ctx context.Context, key string, values interface{}) (int64, error)
- func (r *RedisClient) HSetNX(ctx context.Context, key, field string, value interface{}) (bool, error)
- func (r *RedisClient) HVals(ctx context.Context, key string) ([]string, error)
- func (r *RedisClient) Incr(ctx context.Context, key string) (int64, error)
- func (r *RedisClient) IncrBy(ctx context.Context, key string, val int64) (int64, error)
- func (r *RedisClient) MGet(ctx context.Context, keys ...string) ([]interface{}, error)
- func (r *RedisClient) MSet(ctx context.Context, values ...interface{}) (bool, error)
- func (r *RedisClient) MSetNX(ctx context.Context, values ...interface{}) (bool, error)
- func (r *RedisClient) PTTL(ctx context.Context, key string) (time.Duration, error)
- func (r *RedisClient) SAdd(ctx context.Context, key string, members ...interface{}) (int64, error)
- func (r *RedisClient) SAllMembers(ctx context.Context, key string) ([]string, error)
- func (r *RedisClient) SISMemberIn(ctx context.Context, key string, members interface{}) (bool, error)
- func (r *RedisClient) SISMembersIn(ctx context.Context, key string, members ...interface{}) ([]bool, error)
- func (r *RedisClient) SRem(ctx context.Context, key string, members ...interface{}) (int64, error)
- func (r *RedisClient) Set(ctx context.Context, key string, value interface{}) (bool, error)
- func (r *RedisClient) SetNX(ctx context.Context, key string, value interface{}) (bool, error)
- func (r *RedisClient) SetNXWithExpire(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
- func (r *RedisClient) SetWithExpire(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
- func (r *RedisClient) String(ctx context.Context) string
- func (r *RedisClient) TTL(ctx context.Context, key string) (time.Duration, error)
- func (r *RedisClient) ZAdd(ctx context.Context, key string, z []*redis.Z) (int64, error)
- func (r *RedisClient) ZAddNX(ctx context.Context, key string, z []*redis.Z) (int64, error)
- func (r *RedisClient) ZCount(ctx context.Context, key string, minScore int64, maxScore int64) (int64, error)
- func (r *RedisClient) ZDiff(ctx context.Context, keys ...string) ([]string, error)
- func (r *RedisClient) ZRange(ctx context.Context, key string, startNum int64, stopNum int64) ([]string, error)
- func (r *RedisClient) ZRangeWithScores(ctx context.Context, key string, start int64, stop int64) ([]redis.Z, error)
- func (r *RedisClient) ZRem(ctx context.Context, key string, members ...interface{}) (int64, error)
- func (r *RedisClient) ZRemRangeByScore(ctx context.Context, key string, minScore int64, maxScore int64) (int64, error)
- func (r *RedisClient) ZRevRange(ctx context.Context, key string, startNum int64, stopNum int64) ([]string, error)
- func (r *RedisClient) ZScore(ctx context.Context, key string, member string) (float64, error)
Constants ¶
const ( //keep ttl KEEPTTL = -1 //client_or_sentinel CLIENT_OR_SENTINEL = 1 //cluster CLUSTER = 2 )
const (
Spe = "||"
)
Variables ¶
This section is empty.
Functions ¶
func InitClient ¶
func InitClusterClient ¶
func InitClusterClient(name string, cli *redis.ClusterClient)
Types ¶
type Mutex ¶
type Mutex struct { sync.Mutex *RedisClient *time.Ticker // contains filtered or unexported fields }
func NewMutex ¶
func NewMutex(cli *RedisClient, timerSecond, watchTimeSecond int) *Mutex
lockTime add lockTime to key, maxTime = maxCount(10)*lockTimeSecond
func (*Mutex) LockRenewal ¶
type RedisClient ¶
type RedisClient struct {
// contains filtered or unexported fields
}
func GetClient ¶
func GetClient(name string) *RedisClient
func (*RedisClient) Client ¶
func (r *RedisClient) Client() *redis.Client
******************** client ********************** get redis client ;it can be nil
func (*RedisClient) ClusterClient ¶
func (r *RedisClient) ClusterClient() *redis.ClusterClient
get redis clusterClient;it can be nil
func (*RedisClient) Eval ¶
func (r *RedisClient) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
script like return {KEYS[1],ARGV[1]}", []string{"key"}, "hello") example:
scrp := `return redis.call(KEYS[1],ARGV[1],ARGV[2],ARGV[3])` s, err := r.GetClient(Name).Eval(context.TODO(), scrp, []string{"mget"}, "g10", "g11", "g12")
*
func (*RedisClient) Expire ¶
func (r *RedisClient) Expire(ctx context.Context, key string, expiration time.Duration) (bool, error)
set expireTime
func (*RedisClient) GeoAdd ¶
func (r *RedisClient) GeoAdd(ctx context.Context, key string, geoLocation ...*redis.GeoLocation) (int64, error)
func (*RedisClient) GeoRadius ¶
func (r *RedisClient) GeoRadius(ctx context.Context, key string, longitude float64, latitude float64, query *redis.GeoRadiusQuery) ([]redis.GeoLocation, error)
func (*RedisClient) GeoRadiusByMember ¶
func (r *RedisClient) GeoRadiusByMember(ctx context.Context, key string, member string, query *redis.GeoRadiusQuery) ([]redis.GeoLocation, error)
func (*RedisClient) GeoRadiusByMemberStore ¶
func (r *RedisClient) GeoRadiusByMemberStore(ctx context.Context, key string, member string, query *redis.GeoRadiusQuery) (int64, error)
func (*RedisClient) GeoRadiusStore ¶
func (r *RedisClient) GeoRadiusStore(ctx context.Context, key string, longitude float64, latitude float64, query *redis.GeoRadiusQuery) (int64, error)
func (*RedisClient) GetEx ¶
func (r *RedisClient) GetEx(ctx context.Context, key string, expiration time.Duration) (string, error)
Get Val and Set expireTime ,expiration > 0; expiration = 0 not expire Requires Redis >= 6.2.0.
func (*RedisClient) HIncrBy ¶
func (r *RedisClient) HIncrBy(ctx context.Context, key string, field string, incr int64) (int64, error)
return increment ++num, bug the value must an integer Type ;Counter;
func (*RedisClient) HIncrByFloat ¶
func (r *RedisClient) HIncrByFloat(ctx context.Context, key string, field string, incr float64) (float64, error)
return increment ++num, bug the value must an integer Type ;Counter
func (*RedisClient) HMGet ¶
func (r *RedisClient) HMGet(ctx context.Context, key string, field ...string) ([]interface{}, error)
val is nil where key not exit in []interface{}{}
func (*RedisClient) HSet ¶
HSet accepts values in following formats:
- HSet("myhash", "key1", "value1", "key2", "value2")
- HSet("myhash", []string{"key1", "value1", "key2", "value2"})
- HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})
If the value exists, count will not +1 return set succ num
func (*RedisClient) HSetNX ¶
func (r *RedisClient) HSetNX(ctx context.Context, key, field string, value interface{}) (bool, error)
return true where set succ
func (*RedisClient) MGet ¶
func (r *RedisClient) MGet(ctx context.Context, keys ...string) ([]interface{}, error)
Get Vals, - keys like ["a","b","c","d"] , vals like [aa,bb,cc,nil] ,val is nil where key not exit
func (*RedisClient) MSet ¶
func (r *RedisClient) MSet(ctx context.Context, values ...interface{}) (bool, error)
MSet is like Set but accepts multiple values:
- MSet("key1", "value1", "key2", "value2") - MSet([]string{"key1", "value1", "key2", "value2"}) - MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})
func (*RedisClient) MSetNX ¶
func (r *RedisClient) MSetNX(ctx context.Context, values ...interface{}) (bool, error)
MSetNX is like SetNX but accepts multiple values:
- MSetNX("key1", "value1", "key2", "value2")
- MSetNX([]string{"key1", "value1", "key2", "value2"})
- MSetNX(map[string]interface{}{"key1": "value1", "key2": "value2"})
func (*RedisClient) SAllMembers ¶
get all member
func (*RedisClient) SISMemberIn ¶
func (r *RedisClient) SISMemberIn(ctx context.Context, key string, members interface{}) (bool, error)
return true if member in set
func (*RedisClient) SISMembersIn ¶
func (r *RedisClient) SISMembersIn(ctx context.Context, key string, members ...interface{}) ([]bool, error)
return true if member in set ; version >= 6.2.0.
func (*RedisClient) SetNXWithExpire ¶
func (r *RedisClient) SetNXWithExpire(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
SetNX One expireTime default 0; expiration=0 ,not expire ; expiration>0 , expire ; version >= 6.0 if you set expireTime=-1
func (*RedisClient) SetWithExpire ¶
func (r *RedisClient) SetWithExpire(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
Set Val with expiretime; - it does not expire where expireTime = 0; - version >= 6.0 if you set expireTime=-1
func (*RedisClient) ZAddNX ¶
add value if not exits return succ count; count will not +1 where Z exits; value unique
func (*RedisClient) ZCount ¶
func (r *RedisClient) ZCount(ctx context.Context, key string, minScore int64, maxScore int64) (int64, error)
get count with Score Range
func (*RedisClient) ZRange ¶
func (r *RedisClient) ZRange(ctx context.Context, key string, startNum int64, stopNum int64) ([]string, error)
sort value ; like bottom n
func (*RedisClient) ZRangeWithScores ¶
func (r *RedisClient) ZRangeWithScores(ctx context.Context, key string, start int64, stop int64) ([]redis.Z, error)
range with score ;start<= x <=stop
func (*RedisClient) ZRemRangeByScore ¶
func (r *RedisClient) ZRemRangeByScore(ctx context.Context, key string, minScore int64, maxScore int64) (int64, error)
del where score between min and max min <= max return succ num