Documentation ¶
Index ¶
- Constants
- type Config
- type Redis
- func (r *Redis) Close() (err error)
- func (r *Redis) Cluster() *redis.ClusterClient
- func (r *Redis) Decr(ctx context.Context, key string) bool
- func (r *Redis) Del(ctx context.Context, key ...string) int64
- func (r *Redis) DelWithErr(ctx context.Context, key string) (int64, error)
- func (r *Redis) Exists(ctx context.Context, key string) bool
- func (r *Redis) ExistsWithErr(ctx context.Context, key string) (bool, error)
- func (r *Redis) Expire(ctx context.Context, key string, expiration time.Duration) (bool, error)
- func (r *Redis) GeoAdd(ctx context.Context, key string, location *redis.GeoLocation) (int64, error)
- func (r *Redis) GeoRadius(ctx context.Context, key string, longitude, latitude float64, ...) ([]redis.GeoLocation, error)
- func (r *Redis) Get(ctx context.Context, key string) string
- func (r *Redis) GetRaw(ctx context.Context, key string) ([]byte, error)
- func (r *Redis) HDel(ctx context.Context, key string, field ...string) bool
- func (r *Redis) HGet(ctx context.Context, key string, fields string) (string, error)
- func (r *Redis) HGetAll(ctx context.Context, key string) map[string]string
- func (r *Redis) HIncrBy(ctx context.Context, key string, field string, incr int) int64
- func (r *Redis) HIncrByWithErr(ctx context.Context, key string, field string, incr int) (int64, error)
- func (r *Redis) HKeys(ctx context.Context, key string) []string
- func (r *Redis) HLen(ctx context.Context, key string) int64
- func (r *Redis) HMGet(ctx context.Context, key string, fields []string) []string
- func (r *Redis) HMGetMap(ctx context.Context, key string, fields []string) map[string]string
- func (r *Redis) HSet(ctx context.Context, key string, value ...interface{}) bool
- func (r *Redis) Incr(ctx context.Context, key string) bool
- func (r *Redis) IncrBy(ctx context.Context, key string, increment int64) (int64, error)
- func (r *Redis) IncrWithErr(ctx context.Context, key string) (int64, error)
- func (r *Redis) LIndex(ctx context.Context, key string, idx int64) (string, error)
- func (r *Redis) LLen(ctx context.Context, key string) int64
- func (r *Redis) LLenWithErr(ctx context.Context, key string) (int64, error)
- func (r *Redis) LPush(ctx context.Context, key string, values ...interface{}) (int64, error)
- func (r *Redis) LRange(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (r *Redis) LRem(ctx context.Context, key string, count int64, value interface{}) int64
- func (r *Redis) LTrim(ctx context.Context, key string, start, stop int64) (string, error)
- func (r *Redis) MGet(ctx context.Context, keys ...string) ([]string, error)
- func (r *Redis) MGets(ctx context.Context, keys []string) ([]interface{}, error)
- func (r *Redis) RPop(ctx context.Context, key string) (string, error)
- func (r *Redis) RPush(ctx context.Context, key string, values ...interface{}) (int64, error)
- func (r *Redis) SAdd(ctx context.Context, key string, member ...interface{}) (int64, error)
- func (r *Redis) SIsMember(ctx context.Context, key string, member interface{}) (bool, error)
- func (r *Redis) SMembers(ctx context.Context, key string) ([]string, error)
- func (r *Redis) Set(ctx context.Context, key string, value interface{}, expire time.Duration) bool
- func (r *Redis) SetNx(ctx context.Context, key string, value interface{}, expiration time.Duration) bool
- func (r *Redis) SetNxWithErr(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
- func (r *Redis) SetWithErr(ctx context.Context, key string, value interface{}, expire time.Duration) error
- func (r *Redis) Stub() *redis.Client
- func (r *Redis) TTL(ctx context.Context, key string) (int64, error)
- func (r *Redis) Type(ctx context.Context, key string) (string, error)
- func (r *Redis) ZAdd(ctx context.Context, key string, members ...*redis.Z) (int64, error)
- func (r *Redis) ZCard(ctx context.Context, key string) (int64, error)
- func (r *Redis) ZCount(ctx context.Context, key string, min, max string) (int64, error)
- func (r *Redis) ZRange(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (r *Redis) ZRem(ctx context.Context, key string, members ...interface{}) (int64, error)
- func (r *Redis) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) (int64, error)
- func (r *Redis) ZRevRange(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (r *Redis) ZRevRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) ([]string, error)
- func (r *Redis) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) ([]redis.Z, error)
- func (r *Redis) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]redis.Z, error)
- func (r *Redis) ZRevRank(ctx context.Context, key string, member string) (int64, error)
- func (r *Redis) ZScore(ctx context.Context, key string, member string) (float64, error)
- type WrapLogger
Constants ¶
const ( //ClusterMode using clusterClient ClusterMode string = "cluster" //StubMode using redisClient StubMode string = "stub" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Addrs 实例配置地址 Addrs []string // Mode Redis模式 cluster|stub Mode string // Password 密码 Password string // DB,默认为0, 一般应用不推荐使用DB分片 DB int // PoolSize 集群内每个节点的最大连接池限制 默认每个CPU10个连接 PoolSize int // MaxRetries 网络相关的错误最大重试次数 默认8次 MaxRetries int // MinIdleConns 最小空闲连接数 MinIdleConns int // DialTimeout 拨超时时间 DialTimeout time.Duration // ReadTimeout 读超时 默认3s ReadTimeout time.Duration // WriteTimeout 读超时 默认3s WriteTimeout time.Duration // IdleTimeout 连接最大空闲时间,默认60s, 超过该时间,连接会被主动关闭 IdleTimeout time.Duration // Debug开关 Debug bool // ReadOnly 集群模式 在从属节点上启用读模式 ReadOnly bool // 慢日志门限值,超过该门限值的请求,将被记录到慢日志中 SlowThreshold time.Duration }
Config for redis, contains RedisStubConfig and RedisClusterConfig
type Redis ¶
type Redis struct { Config *Config Client redis.Cmdable }
Redis client
func (*Redis) 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 (*Redis) Cluster ¶
func (r *Redis) Cluster() *redis.ClusterClient
Cluster try to get a redis.ClusterClient
func (*Redis) DelWithErr ¶
DelWithErr ...
func (*Redis) ExistsWithErr ¶
ExistsWithErr ...
func (*Redis) GeoRadius ¶
func (r *Redis) GeoRadius(ctx context.Context, key string, longitude, latitude float64, query *redis.GeoRadiusQuery) ([]redis.GeoLocation, error)
GeoRadius 根据经纬度查询列表
func (*Redis) HIncrByWithErr ¶
func (r *Redis) HIncrByWithErr(ctx context.Context, key string, field string, incr int) (int64, error)
HIncrByWithErr 哈希field自增并且返回错误
func (*Redis) 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"})
Note that it requires Redis v4 for multiple field/value pairs support.
func (*Redis) IncrWithErr ¶
IncrWithErr ...
func (*Redis) LLenWithErr ¶
LLenWithErr ...
func (*Redis) SetNx ¶
func (r *Redis) SetNx(ctx context.Context, key string, value interface{}, expiration time.Duration) bool
SetNx 设置redis的string 如果键已存在
func (*Redis) SetNxWithErr ¶
func (r *Redis) SetNxWithErr(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
SetNxWithErr 设置redis的string 如果键已存在
func (*Redis) SetWithErr ¶
func (r *Redis) SetWithErr(ctx context.Context, key string, value interface{}, expire time.Duration) error
SetWithErr ...
func (*Redis) ZRemRangeByRank ¶
ZRemRangeByRank 移除有序集合中给定的排名区间的所有成员
func (*Redis) ZRevRangeByScore ¶
func (r *Redis) ZRevRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) ([]string, error)
ZRevRangeByScore ...
func (*Redis) ZRevRangeByScoreWithScores ¶
func (r *Redis) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) ([]redis.Z, error)
ZRevRangeByScoreWithScores ...
func (*Redis) ZRevRangeWithScores ¶
func (r *Redis) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]redis.Z, error)
ZRevRangeWithScores ...
type WrapLogger ¶
type WrapLogger struct{}