Documentation ¶
Index ¶
- Variables
- func NewRedisPool(addr string, pwd string, db int, maxIdle int, maxActive int, ...) *redis.Pool
- type RedisCache
- func (c *RedisCache) Decr(ctx context.Context, key string, expire int64) (int64, error)
- func (c *RedisCache) DecrBy(ctx context.Context, key string, value int64, expire int64) (int64, error)
- func (c *RedisCache) Del(ctx context.Context, key string) error
- func (c *RedisCache) Do(ctx context.Context, commandName string, args ...interface{}) (reply interface{}, err error)
- func (c *RedisCache) Exists(ctx context.Context, key string) (bool, error)
- func (c *RedisCache) Get(ctx context.Context, key string) (interface{}, error)
- func (c *RedisCache) GetFloat64(ctx context.Context, key string) (float64, error)
- func (c *RedisCache) GetInt(ctx context.Context, key string) (int, error)
- func (c *RedisCache) GetInt64(ctx context.Context, key string) (int64, error)
- func (c *RedisCache) GetInt64s(ctx context.Context, keys ...interface{}) (map[string]int64, error)
- func (c *RedisCache) GetInts(ctx context.Context, keys ...interface{}) (map[string]int, error)
- func (c *RedisCache) GetString(ctx context.Context, key string) (string, error)
- func (c *RedisCache) GetStrings(ctx context.Context, keys ...interface{}) (map[string]string, error)
- func (c *RedisCache) GetUint64(ctx context.Context, key string) (uint64, error)
- func (c *RedisCache) Gets(ctx context.Context, keys ...string) (map[string]interface{}, error)
- func (c *RedisCache) HDecrBy(ctx context.Context, key string, field string, value int64, expire int64) (int64, error)
- func (c *RedisCache) HGet(ctx context.Context, key string, field string) (interface{}, error)
- func (c *RedisCache) HGetAll(ctx context.Context, key interface{}, obj interface{}) error
- func (c *RedisCache) HIncrBy(ctx context.Context, key string, field string, value int64, expire int64) (int64, error)
- func (c *RedisCache) HMGet(ctx context.Context, key interface{}, fieldNames ...interface{}) (map[string]interface{}, error)
- func (c *RedisCache) HMGetObj(ctx context.Context, obj interface{}, key string, fieldNames ...string) (notFound bool, err error)
- func (c *RedisCache) HMSet(ctx context.Context, key string, fields map[string]interface{}, expire int64) error
- func (c *RedisCache) HMSetObj(ctx context.Context, key string, obj interface{}, expire int64) error
- func (c *RedisCache) HSet(ctx context.Context, key string, field string, value interface{}, expire int64) error
- func (c *RedisCache) HSetEmptyValue(ctx context.Context, key string, expire int64) error
- func (c *RedisCache) Incr(ctx context.Context, key string, expire int64) (int64, error)
- func (c *RedisCache) IncrBy(ctx context.Context, key string, value int64, expire int64) (int64, error)
- func (c *RedisCache) Keys(ctx context.Context, key string) ([]string, error)
- func (c *RedisCache) Ping() error
- func (c *RedisCache) ScanStruct(src []interface{}, dest interface{}, fields []string) (err error)
- func (c *RedisCache) Set(ctx context.Context, key string, val interface{}, expire int64) error
- func (c *RedisCache) SetExpire(ctx context.Context, key string, expire int64) error
- func (c *RedisCache) Setup(conf config.IConfig) (*RedisCache, error)
- func (c *RedisCache) Version() string
- func (c *RedisCache) ZAdd(ctx context.Context, key string, score int64, member string) (reply interface{}, err error)
- func (c *RedisCache) ZRange(ctx context.Context, key string, from, to int64) (map[string]int64, error)
- func (c *RedisCache) ZRangeByScore(ctx context.Context, key string, from, to, offset int64, count int) (map[string]int64, error)
- func (c *RedisCache) ZRank(ctx context.Context, key, member string) (int64, error)
- func (c *RedisCache) ZRem(ctx context.Context, key string, member string) (reply interface{}, err error)
- func (c *RedisCache) ZRevrange(ctx context.Context, key string, from, to int64) (map[string]int64, error)
- func (c *RedisCache) ZRevrangeByScore(ctx context.Context, key string, from, to, offset int64, count int) (map[string]int64, error)
- func (c *RedisCache) ZRevrank(ctx context.Context, key, member string) (int64, error)
- func (c *RedisCache) ZScore(ctx context.Context, key string, member string) (int64, error)
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyCached = errors.New("redis: cached nil")
ErrEmptyCached 击穿命中的时候触发
Functions ¶
Types ¶
type RedisCache ¶
RedisCache use redis as cache
func NewRedisCache ¶
func NewRedisCache(conf config.IConfig) (*RedisCache, error)
NewRedisCache create redis cache instance
func (*RedisCache) DecrBy ¶
func (c *RedisCache) DecrBy(ctx context.Context, key string, value int64, expire int64) (int64, error)
DecrBy auto-Decrement get key and set v--
func (*RedisCache) Del ¶
func (c *RedisCache) Del(ctx context.Context, key string) error
Del key from cache
func (*RedisCache) Do ¶
func (c *RedisCache) Do(ctx context.Context, commandName string, args ...interface{}) (reply interface{}, err error)
Do command to exec custom command if redis return redis.ErrNil should convert to value null and err null
func (*RedisCache) Get ¶
func (c *RedisCache) Get(ctx context.Context, key string) (interface{}, error)
Get command to get value from cache, control with context
func (*RedisCache) GetFloat64 ¶
GetFloat64 command
func (*RedisCache) GetStrings ¶
func (c *RedisCache) GetStrings(ctx context.Context, keys ...interface{}) (map[string]string, error)
GetStrings command
func (*RedisCache) HGetAll ¶
func (c *RedisCache) HGetAll(ctx context.Context, key interface{}, obj interface{}) error
HGetAll get OBJECT from redis
func (*RedisCache) HMGet ¶
func (c *RedisCache) HMGet(ctx context.Context, key interface{}, fieldNames ...interface{}) (map[string]interface{}, error)
HMGet 批量获取字段 1.get failed ,return nil, err 2.not found return nil,nil,3.get result return result,nil
func (*RedisCache) HMGetObj ¶
func (c *RedisCache) HMGetObj(ctx context.Context, obj interface{}, key string, fieldNames ...string) (notFound bool, err error)
HMGetObj 获取结构体
func (*RedisCache) HMSet ¶
func (c *RedisCache) HMSet(ctx context.Context, key string, fields map[string]interface{}, expire int64) error
HMSet 批量添加字段
func (*RedisCache) HSetEmptyValue ¶
HSetEmptyValue 设置空值,防止缓存击穿
func (*RedisCache) IncrBy ¶
func (c *RedisCache) IncrBy(ctx context.Context, key string, value int64, expire int64) (int64, error)
IncrBy auto-Increment get key and set v++
func (*RedisCache) ScanStruct ¶
func (c *RedisCache) ScanStruct(src []interface{}, dest interface{}, fields []string) (err error)
ScanStruct 为hmget返回值拼装数据,values返回非[k,v,k,v]数组
func (*RedisCache) Set ¶
Set command to set value to cache,key is string, if expire(second) is setted bigger than 0, than key will have Expire time, in seconds,
func (*RedisCache) Setup ¶
func (c *RedisCache) Setup(conf config.IConfig) (*RedisCache, error)
Setup init cache with config
func (*RedisCache) ZAdd ¶
func (c *RedisCache) ZAdd(ctx context.Context, key string, score int64, member string) (reply interface{}, err error)
ZAdd 将一个 member 元素及其 score 值加入到有序集 key 当中。
func (*RedisCache) ZRange ¶
func (c *RedisCache) ZRange(ctx context.Context, key string, from, to int64) (map[string]int64, error)
ZRange 返回有序集中,指定区间内的成员。其中成员的位置按分数值递增(从小到大)来排序。具有相同分数值的成员按字典序(lexicographical order )来排列。 以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,以此类推。或 以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推。
func (*RedisCache) ZRangeByScore ¶
func (c *RedisCache) ZRangeByScore(ctx context.Context, key string, from, to, offset int64, count int) (map[string]int64, error)
ZRangeByScore 返回有序集合中指定分数区间的成员列表。有序集成员按分数值递增(从小到大)次序排列。 具有相同分数值的成员按字典序来排列
func (*RedisCache) ZRem ¶
func (c *RedisCache) ZRem(ctx context.Context, key string, member string) (reply interface{}, err error)
ZRem 移除有序集 key 中的一个成员,不存在的成员将被忽略。
func (*RedisCache) ZRevrange ¶
func (c *RedisCache) ZRevrange(ctx context.Context, key string, from, to int64) (map[string]int64, error)
ZRevrange 返回有序集中,指定区间内的成员。其中成员的位置按分数值递减(从大到小)来排列。具有相同分数值的成员按字典序(lexicographical order )来排列。 以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,以此类推。或 以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推。
func (*RedisCache) ZRevrangeByScore ¶
func (c *RedisCache) ZRevrangeByScore(ctx context.Context, key string, from, to, offset int64, count int) (map[string]int64, error)
ZRevrangeByScore 返回有序集中指定分数区间内的所有的成员。有序集成员按分数值递减(从大到小)的次序排列。 具有相同分数值的成员按字典序来排列