redis

package
v1.3.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (

	// Nil is an alias of redis.Nil
	Nil = redis.Nil
)

Variables

View Source
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 IntCmd added in v1.3.0

type IntCmd = redis.IntCmd

IntCmd is an alias of redis.IntCmd

type IntSliceCmd added in v1.3.0

type IntSliceCmd = redis.IntSliceCmd

IntSliceCmd is an alias of redis.IntSliceCmd

type Pair added in v1.3.0

type Pair struct {
	Member string
	Score  int64
}

Pair zset pair element

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

func New(cfg *Config) (rdb *Redis, err error)

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

func (r *Redis) Close() (err error)

Close closes the client, releasing any open resources

func (*Redis) Del added in v1.3.0

func (r *Redis) Del(ctx context.Context, keys ...string) (num int64, err error)

Del removes the specified keys, a key is ignored if it does not exist

func (*Redis) Exists added in v1.3.0

func (r *Redis) Exists(ctx context.Context, key string) (value bool, err error)

Exists returns if key exists

func (*Redis) Expire added in v1.3.0

func (r *Redis) Expire(ctx context.Context, key string, seconds int) (err error)

Expire set a seconds timeout on key

func (*Redis) ForceUnLock

func (r *Redis) ForceUnLock(ctx context.Context, key string) error

ForceUnLock force unlock resource

func (*Redis) Get added in v1.3.0

func (r *Redis) Get(ctx context.Context, key string) (value string, err error)

Get get the value of key. If the key does not exist the special value nil is returned

func (*Redis) HDel added in v1.3.0

func (r *Redis) HDel(ctx context.Context, key string, fields ...string) (value int64, err error)

HDel removes the specified fields from the hash stored at key

func (*Redis) HExists added in v1.3.0

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

HExists returns if field is an existing field in the hash stored at key

func (*Redis) HGet added in v1.3.0

func (r *Redis) HGet(ctx context.Context, key string, field string) (value string, err error)

HGet returns the value associated with field in the hash stored at key

func (*Redis) HGetAll added in v1.3.0

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

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) HKeys added in v1.3.0

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

HKeys returns all field names in the hash stored at key

func (*Redis) HLen added in v1.3.0

func (r *Redis) HLen(ctx context.Context, key string) (value int64, err error)

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

func (r *Redis) HMSet(ctx context.Context, key string, kvs map[string]string) (err error)

HMSet sets the specified fields to their respective values in the hash stored at key

func (*Redis) HSet added in v1.3.0

func (r *Redis) HSet(ctx context.Context, key string, field string, value string) (err error)

HSet sets field in the hash stored at key to value

func (*Redis) IncrBy added in v1.3.0

func (r *Redis) IncrBy(ctx context.Context, key string, increment int64) (value int64, err error)

IncrBy increments the number stored at key by increment

func (*Redis) LIndex added in v1.3.0

func (r *Redis) LIndex(ctx context.Context, key string, index int64) (value string, err error)

LIndex returns the element at index index in the list stored at key

func (*Redis) LLen added in v1.3.0

func (r *Redis) LLen(ctx context.Context, key string) (value int64, err error)

LLen returns the length of the list stored at key

func (*Redis) LPop added in v1.3.0

func (r *Redis) LPop(ctx context.Context, key string) (value string, err error)

LPop removes and returns the first elements of the list stored at key

func (*Redis) LPopN added in v1.3.2

func (r *Redis) LPopN(ctx context.Context, key string, count int) (value []string, err error)

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) MGet added in v1.3.0

func (r *Redis) MGet(ctx context.Context, keys ...string) (value []string, err error)

MGet the values of all specified keys

func (*Redis) MSet added in v1.3.0

func (r *Redis) MSet(ctx context.Context, kvs map[string]string) (err error)

MSet sets the given keys to their respective values

func (*Redis) Ping added in v0.2.0

func (r *Redis) Ping(ctx context.Context) (alive bool)

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

func (r *Redis) RPop(ctx context.Context, key string) (value string, err error)

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

func (r *Redis) SCard(ctx context.Context, key string) (value int64, err error)

SCard returns the set cardinality (number of elements) of the set stored at key

func (*Redis) SDiff added in v1.3.0

func (r *Redis) SDiff(ctx context.Context, keys ...string) (value []string, err error)

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

func (r *Redis) SIntersect(ctx context.Context, keys ...string) (value []string, err error)

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

func (r *Redis) SMembers(ctx context.Context, key string) (value []string, err error)

SMembers returns all the members of the set value stored at key

func (*Redis) SPop added in v1.3.0

func (r *Redis) SPop(ctx context.Context, key string) (value string, err error)

SPop removes and returns one random members from the set value store at key

func (*Redis) SPopN added in v1.3.0

func (r *Redis) SPopN(ctx context.Context, key string, count int64) (value []string, err error)

SPopN removes and returns count random members from the set value store at key

func (*Redis) SRandMember added in v1.3.0

func (r *Redis) SRandMember(ctx context.Context, key string) (value string, err error)

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

func (r *Redis) SUnion(ctx context.Context, keys ...string) (value []string, err error)

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) Set added in v1.3.0

func (r *Redis) Set(ctx context.Context, key string, value string) (err error)

Set key to hold the string value

func (*Redis) SetEx added in v1.3.0

func (r *Redis) SetEx(ctx context.Context, key string, value string, seconds int) (err error)

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

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

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

func (r *Redis) UnLock(ctx context.Context, key, lockValue string) error

UnLock unlock resource

func (*Redis) ZAdd added in v1.3.0

func (r *Redis) ZAdd(ctx context.Context, key string, pais ...*Pair) (value int64, err error)

ZAdd adds all the specified members with the specified scores to the sorted set

func (*Redis) ZCard added in v1.3.0

func (r *Redis) ZCard(ctx context.Context, key string) (value int64, err error)

ZCard returns the sorted set number of elements

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

func (r *Redis) ZPopMin(ctx context.Context, key string, count ...int64) (value []*Pair, err error)

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

func (r *Redis) ZRank(ctx context.Context, key string, member string) (value int64, err error)

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

func (*Redis) ZRevRank added in v1.3.0

func (r *Redis) ZRevRank(ctx context.Context, key string, member string) (value int64, err error)

ZRevRank returns the rank of member in the sorted set stored at key with the scores ordered from high to low

func (*Redis) ZScore added in v1.3.0

func (r *Redis) ZScore(ctx context.Context, key string, member string) (value int64, err error)

ZScore returns the score of member in the sorted

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

type Z added in v1.3.0

type Z = redis.Z

Z is an alias of redis.Z

type ZRangeBy added in v1.3.0

type ZRangeBy = redis.ZRangeBy

ZRangeBy is an alias of redis.ZRangeBy

type ZStore added in v1.3.0

type ZStore = redis.ZStore

ZStore is an alias of redis.ZStore

Jump to

Keyboard shortcuts

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