goredis

package
v0.0.0-...-91d00df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//keep ttl
	KEEPTTL = -1
	//client_or_sentinel
	CLIENT_OR_SENTINEL = 1
	//cluster
	CLUSTER = 2
)
View Source
const (
	Spe = "||"
)

Variables

This section is empty.

Functions

func InitClient

func InitClient(name string, cli *redis.Client)

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) Lock

func (m *Mutex) Lock(ctx context.Context, key string, second int) (bool, error)

func (*Mutex) LockRenewal

func (m *Mutex) LockRenewal(ctx context.Context, key string) (lock bool, val string, err error)

func (*Mutex) UnLock

func (m *Mutex) UnLock(ctx context.Context, key string) (bool, error)

unlock yourself lock, val is unique

func (*Mutex) UnLockRenewal

func (m *Mutex) UnLockRenewal(ctx context.Context, key, val string) (bool, error)

unlock yourself lock, val is unique

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) Decr

func (r *RedisClient) Decr(ctx context.Context, key string) (int64, error)

val-1

func (*RedisClient) DecrBy

func (r *RedisClient) DecrBy(ctx context.Context, key string, val int64) (int64, error)

val-n

func (*RedisClient) Del

func (r *RedisClient) Del(ctx context.Context, keys ...string) (int64, error)

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) EvalSha

func (r *RedisClient) EvalSha(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)

func (*RedisClient) Exists

func (r *RedisClient) Exists(ctx context.Context, keys ...string) (int64, error)

key is exits

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) GeoDist

func (r *RedisClient) GeoDist(ctx context.Context, key string, member1 string, member2 string, unit string) (float64, error)

func (*RedisClient) GeoHash

func (r *RedisClient) GeoHash(ctx context.Context, key string, members ...string) ([]string, error)

func (*RedisClient) GeoPos

func (r *RedisClient) GeoPos(ctx context.Context, key string, members ...string) ([]*redis.GeoPos, 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) Get

func (r *RedisClient) Get(ctx context.Context, key string) (string, error)

Get Val

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) HDel

func (r *RedisClient) HDel(ctx context.Context, key string, field ...string) (int64, error)

return del succ num

func (*RedisClient) HExists

func (r *RedisClient) HExists(ctx context.Context, key string, field string) (bool, error)

func (*RedisClient) HGetAll

func (r *RedisClient) HGetAll(ctx context.Context, key string) (map[string]string, error)

func (*RedisClient) HGetOne

func (r *RedisClient) HGetOne(ctx context.Context, key string, field string) (string, error)

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) HKeys

func (r *RedisClient) HKeys(ctx context.Context, key string) ([]string, error)

return hash keys

func (*RedisClient) HLen

func (r *RedisClient) HLen(ctx context.Context, key string) (int64, error)

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

func (r *RedisClient) HSet(ctx context.Context, key string, values interface{}) (int64, error)

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) HVals

func (r *RedisClient) HVals(ctx context.Context, key string) ([]string, error)

get all values

func (*RedisClient) Incr

func (r *RedisClient) Incr(ctx context.Context, key string) (int64, error)

val+1

func (*RedisClient) IncrBy

func (r *RedisClient) IncrBy(ctx context.Context, key string, val int64) (int64, error)

val+n

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) PTTL

func (r *RedisClient) PTTL(ctx context.Context, key string) (time.Duration, error)

return expireTime with Millisecond

func (*RedisClient) SAdd

func (r *RedisClient) SAdd(ctx context.Context, key string, members ...interface{}) (int64, error)

func (*RedisClient) SAllMembers

func (r *RedisClient) SAllMembers(ctx context.Context, key string) ([]string, error)

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) SRem

func (r *RedisClient) SRem(ctx context.Context, key string, members ...interface{}) (int64, error)

func (*RedisClient) Set

func (r *RedisClient) Set(ctx context.Context, key string, value interface{}) (bool, error)

Set Val;

func (*RedisClient) SetNX

func (r *RedisClient) SetNX(ctx context.Context, key string, value interface{}) (bool, error)

SetNX One

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) String

func (r *RedisClient) String(ctx context.Context) string

func (*RedisClient) TTL

func (r *RedisClient) TTL(ctx context.Context, key string) (time.Duration, error)

return expireTime with second

func (*RedisClient) ZAdd

func (r *RedisClient) ZAdd(ctx context.Context, key string, z []*redis.Z) (int64, error)

return succ count; count will not +1 where Z exits; value unique

func (*RedisClient) ZAddNX

func (r *RedisClient) ZAddNX(ctx context.Context, key string, z []*redis.Z) (int64, error)

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) ZDiff

func (r *RedisClient) ZDiff(ctx context.Context, keys ...string) ([]string, error)

version >= 6.2.0.

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) ZRem

func (r *RedisClient) ZRem(ctx context.Context, key string, members ...interface{}) (int64, error)

return del succ count; count will not +1 where Z exits;

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

func (*RedisClient) ZRevRange

func (r *RedisClient) ZRevRange(ctx context.Context, key string, startNum int64, stopNum int64) ([]string, error)

Reverse sort value by score ;like top n

func (*RedisClient) ZScore

func (r *RedisClient) ZScore(ctx context.Context, key string, member string) (float64, error)

get score with member

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL