Documentation ¶
Index ¶
- Constants
- func DefaultConfig() *config
- type Component
- func (r *Component) Client() redis.Cmdable
- func (r *Component) Close() (err error)
- func (r *Component) Cluster() *redis.ClusterClient
- func (r *Component) Decr(ctx context.Context, key string) (int64, error)
- func (r *Component) DecrBy(ctx context.Context, key string, decrement int64) (int64, error)
- func (r *Component) Del(ctx context.Context, key string) (int64, error)
- func (r *Component) Exists(ctx context.Context, key string) (bool, error)
- func (r *Component) Expire(ctx context.Context, key string, expiration time.Duration) (bool, error)
- func (r *Component) GeoAdd(ctx context.Context, key string, location *redis.GeoLocation) (int64, error)
- func (r *Component) GeoRadius(ctx context.Context, key string, longitude, latitude float64, ...) ([]redis.GeoLocation, error)
- func (r *Component) Get(ctx context.Context, key string) (string, error)
- func (r *Component) GetBytes(ctx context.Context, key string) ([]byte, error)
- func (r *Component) GetEx(ctx context.Context, key string, expire time.Duration) (string, error)
- func (r *Component) HDel(ctx context.Context, key string, field ...string) error
- func (r *Component) HGet(ctx context.Context, key string, fields string) (string, error)
- func (r *Component) HGetAll(ctx context.Context, key string) (map[string]string, error)
- func (r *Component) HIncrBy(ctx context.Context, key string, field string, incr int) (int64, error)
- func (r *Component) HKeys(ctx context.Context, key string) ([]string, error)
- func (r *Component) HLen(ctx context.Context, key string) (int64, error)
- func (r *Component) HMGet(ctx context.Context, key string, fileds []string) ([]interface{}, error)
- func (r *Component) HMGetMap(ctx context.Context, key string, fields []string) (map[string]string, error)
- func (r *Component) HMGetString(ctx context.Context, key string, fileds []string) ([]string, error)
- func (r *Component) HMSet(ctx context.Context, key string, hash map[string]interface{}, ...) error
- func (r *Component) HSet(ctx context.Context, key string, field string, value interface{}) error
- func (r *Component) Incr(ctx context.Context, key string) (int64, error)
- func (r *Component) IncrBy(ctx context.Context, key string, increment int64) (int64, error)
- func (r *Component) LIndex(ctx context.Context, key string, idx int64) (string, error)
- func (r *Component) LLen(ctx context.Context, key string) (int64, error)
- func (r *Component) LPush(ctx context.Context, key string, values ...interface{}) (int64, error)
- func (r *Component) LRange(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (r *Component) LRem(ctx context.Context, key string, count int64, value interface{}) (int64, error)
- func (r *Component) LTrim(ctx context.Context, key string, start, stop int64) (string, error)
- func (r *Component) LockClient() *lockClient
- func (r *Component) MGet(ctx context.Context, keys []string) ([]interface{}, error)
- func (r *Component) MGetString(ctx context.Context, keys ...string) ([]string, error)
- func (r *Component) Ping(ctx context.Context) (string, error)
- func (r *Component) RPop(ctx context.Context, key string) (string, error)
- func (r *Component) RPush(ctx context.Context, key string, values ...interface{}) (int64, error)
- func (r *Component) SAdd(ctx context.Context, key string, member ...interface{}) (int64, error)
- func (r *Component) SIsMember(ctx context.Context, key string, member interface{}) (bool, error)
- func (r *Component) SMembers(ctx context.Context, key string) ([]string, error)
- func (r *Component) SRem(ctx context.Context, key string, member interface{}) (int64, error)
- func (r *Component) Sentinel() *redis.Client
- func (r *Component) Set(ctx context.Context, key string, value interface{}, expire time.Duration) error
- func (r *Component) SetEX(ctx context.Context, key string, value interface{}, expire time.Duration) error
- func (r *Component) SetNX(ctx context.Context, key string, value interface{}, expire time.Duration) error
- func (r *Component) SetNx(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
- func (r *Component) Stub() *redis.Client
- func (r *Component) TTL(ctx context.Context, key string) (time.Duration, error)
- func (r *Component) Type(ctx context.Context, key string) (string, error)
- func (r *Component) ZAdd(ctx context.Context, key string, members ...*redis.Z) (int64, error)
- func (r *Component) ZCard(ctx context.Context, key string) (int64, error)
- func (r *Component) ZCount(ctx context.Context, key string, min, max string) (int64, error)
- func (r *Component) ZRange(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (r *Component) ZRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) ([]string, error)
- func (r *Component) ZRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) ([]redis.Z, error)
- func (r *Component) ZRangeWithScores(ctx context.Context, key string, start, stop int64) ([]redis.Z, error)
- func (r *Component) ZRem(ctx context.Context, key string, members ...interface{}) (int64, error)
- func (r *Component) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) (int64, error)
- func (r *Component) ZRevRange(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (r *Component) ZRevRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) ([]string, error)
- func (r *Component) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) ([]redis.Z, error)
- func (r *Component) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]redis.Z, error)
- func (r *Component) ZRevRank(ctx context.Context, key string, member string) (int64, error)
- func (r *Component) ZScore(ctx context.Context, key string, member string) (float64, error)
- type Container
- type Err
- type Lock
- type LockOption
- type Option
- type RetryStrategy
Constants ¶
const ( // ClusterMode using clusterClient ClusterMode string = "cluster" // StubMode using stubClient StubMode string = "stub" // SentinelMode using Failover sentinel client SentinelMode string = "sentinel" )
const ( // ErrInvalidParams is returned when parameters is invalid. ErrInvalidParams = Err("invalid params") // ErrNotObtained is returned when a Lock cannot be obtained. ErrNotObtained = Err("redislock: not obtained") // ErrLockNotHeld is returned when trying to release an inactive Lock. ErrLockNotHeld = Err("redislock: lock not held") //Nil reply returned by Redis when key does not exist. Nil = redis.Nil )
const PackageName = "component.eredis"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component client (cmdable and config)
func (*Component) Client ¶
func (r *Component) Client() redis.Cmdable
Client returns a universal redis client(ClusterClient, StubClient or SentinelClient), it depends on you config.
func (*Component) Close ¶
Close closes the cluster client, releasing any open resources.
It is rare to Close a ClusterClient, as the ClusterClient is meant to be long-lived and shared between many goroutines.
func (*Component) Cluster ¶
func (r *Component) Cluster() *redis.ClusterClient
Cluster try to get a redis.ClusterClient
func (*Component) GeoAdd ¶
func (r *Component) GeoAdd(ctx context.Context, key string, location *redis.GeoLocation) (int64, error)
GeoAdd 写入地理位置
func (*Component) GeoRadius ¶
func (r *Component) GeoRadius(ctx context.Context, key string, longitude, latitude float64, query *redis.GeoRadiusQuery) ([]redis.GeoLocation, error)
GeoRadius 根据经纬度查询列表
func (*Component) HMGetMap ¶
func (r *Component) HMGetMap(ctx context.Context, key string, fields []string) (map[string]string, error)
HMGetMap 批量获取hash值,返回map
func (*Component) HMGetString ¶
HMGet 批量获取hash值
func (*Component) HMSet ¶
func (r *Component) HMSet(ctx context.Context, key string, hash map[string]interface{}, expire time.Duration) error
HMSet 设置redis的hash
func (*Component) LRem ¶
func (r *Component) LRem(ctx context.Context, key string, count int64, value interface{}) (int64, error)
LRem ...
func (*Component) LockClient ¶
func (r *Component) LockClient() *lockClient
LockClient gets default distributed Lock client
func (*Component) MGetString ¶
MGet ...
func (*Component) Sentinel ¶
func (r *Component) Sentinel() *redis.Client
Sentinel try to get a redis Failover Sentinel client
func (*Component) Set ¶
func (r *Component) Set(ctx context.Context, key string, value interface{}, expire time.Duration) error
Set 设置redis的string
func (*Component) SetEX ¶
func (r *Component) SetEX(ctx context.Context, key string, value interface{}, expire time.Duration) error
SetEX ...
func (*Component) SetNX ¶
func (r *Component) SetNX(ctx context.Context, key string, value interface{}, expire time.Duration) error
SetNX ...
func (*Component) SetNx ¶
func (r *Component) SetNx(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
SetNx 设置redis的string 如果键已存在
func (*Component) ZCount ¶
ZCount 返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。
func (*Component) ZRangeByScore ¶
func (r *Component) ZRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) ([]string, error)
ZRangeByScore ...
func (*Component) ZRangeByScoreWithScores ¶
func (r *Component) ZRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) ([]redis.Z, error)
ZRangeByScoreWithScores ...
func (*Component) ZRangeWithScores ¶
func (r *Component) ZRangeWithScores(ctx context.Context, key string, start, stop int64) ([]redis.Z, error)
ZRangeWithScores ...
func (*Component) ZRemRangeByRank ¶
func (r *Component) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) (int64, error)
ZRemRangeByRank 移除有序集合中给定的排名区间的所有成员
func (*Component) ZRevRangeByScore ¶
func (r *Component) ZRevRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) ([]string, error)
ZRevRangeByScore ...
func (*Component) ZRevRangeByScoreWithScores ¶
func (r *Component) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) ([]redis.Z, error)
ZRevRangeByScoreWithScores ...
func (*Component) ZRevRangeWithScores ¶
func (r *Component) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]redis.Z, error)
ZRevRangeWithScores ...
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock represents an obtained, distributed Lock.
func (*Lock) Refresh ¶
Refresh extends the Lock with a new TTL. May return ErrNotObtained if refresh is unsuccessful.
type LockOption ¶
type LockOption func(c *lockOption)
func WithLockOptionMetadata ¶
func WithLockOptionMetadata(md string) LockOption
func WithLockOptionRetryStrategy ¶
func WithLockOptionRetryStrategy(retryStrategy RetryStrategy) LockOption
type RetryStrategy ¶
type RetryStrategy interface { // NextBackoff returns the next backoff duration. NextBackoff() time.Duration }
RetryStrategy allows to customise the Lock retry strategy.
func ExponentialBackoffRetry ¶
func ExponentialBackoffRetry(min, max time.Duration) RetryStrategy
ExponentialBackoffRetry strategy is an optimization strategy with a retry time of 2**n milliseconds (n means number of times). You can set a minimum and maximum value, the recommended minimum value is not less than 16ms.
func LimitRetry ¶
func LimitRetry(s RetryStrategy, max int) RetryStrategy
LimitRetry limits the number of retries to max attempts.
func LinearBackoffRetry ¶
func LinearBackoffRetry(backoff time.Duration) RetryStrategy
LinearBackoffRetry allows retries regularly with customized intervals
func NoRetry ¶
func NoRetry() RetryStrategy
--------------------------------No Retry----------------------------------- NoRetry acquire the Lock only once.