redis

package
v0.0.0-...-1a2806f Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyCached = errors.New("redis: cached nil")

ErrEmptyCached 击穿命中的时候触发

Functions

func NewRedisPool

func NewRedisPool(addr string, pwd string, db int, maxIdle int, maxActive int, idleTimeout time.Duration) *redis.Pool

NewRedisPool create redis pool by address(ip:port) and pwd

Types

type RedisCache

type RedisCache struct {
	Conf *cache.Config
	// contains filtered or unexported fields
}

RedisCache use redis as cache

func NewRedisCache

func NewRedisCache(conf config.IConfig) (*RedisCache, error)

NewRedisCache create redis cache instance

func (*RedisCache) Decr

func (c *RedisCache) Decr(ctx context.Context, key string, expire int64) (int64, error)

Decr auto-Decrement get key and set v--

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

func (c *RedisCache) Exists(ctx context.Context, key string) (bool, error)

Exists key in redis, exist return true

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

func (c *RedisCache) GetFloat64(ctx context.Context, key string) (float64, error)

GetFloat64 command

func (*RedisCache) GetInt

func (c *RedisCache) GetInt(ctx context.Context, key string) (int, error)

GetInt command

func (*RedisCache) GetInt64

func (c *RedisCache) GetInt64(ctx context.Context, key string) (int64, error)

GetInt64 command

func (*RedisCache) GetInt64s

func (c *RedisCache) GetInt64s(ctx context.Context, keys ...interface{}) (map[string]int64, error)

GetInt64s command

func (*RedisCache) GetInts

func (c *RedisCache) GetInts(ctx context.Context, keys ...interface{}) (map[string]int, error)

GetInts command

func (*RedisCache) GetString

func (c *RedisCache) GetString(ctx context.Context, key string) (string, error)

GetString command

func (*RedisCache) GetStrings

func (c *RedisCache) GetStrings(ctx context.Context, keys ...interface{}) (map[string]string, error)

GetStrings command

func (*RedisCache) GetUint64

func (c *RedisCache) GetUint64(ctx context.Context, key string) (uint64, error)

GetUint64 command

func (*RedisCache) Gets

func (c *RedisCache) Gets(ctx context.Context, keys ...string) (map[string]interface{}, error)

Gets command to get multi keys from cache

func (*RedisCache) HDecrBy

func (c *RedisCache) HDecrBy(ctx context.Context, key string, field string, value int64, expire int64) (int64, error)

func (*RedisCache) HGet

func (c *RedisCache) HGet(ctx context.Context, key string, field string) (interface{}, error)

func (*RedisCache) HGetAll

func (c *RedisCache) HGetAll(ctx context.Context, key interface{}, obj interface{}) error

HGetAll get OBJECT from redis

func (*RedisCache) HIncrBy

func (c *RedisCache) HIncrBy(ctx context.Context, key string, field string, value int64, expire int64) (int64, error)

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

func (c *RedisCache) HMSetObj(ctx context.Context, key string, obj interface{}, expire int64) error

HMSetObj 批量添加字段

func (*RedisCache) HSet

func (c *RedisCache) HSet(ctx context.Context, key string, field string, value interface{}, expire int64) error

func (*RedisCache) HSetEmptyValue

func (c *RedisCache) HSetEmptyValue(ctx context.Context, key string, expire int64) error

HSetEmptyValue 设置空值,防止缓存击穿

func (*RedisCache) Incr

func (c *RedisCache) Incr(ctx context.Context, key string, expire int64) (int64, error)

Incr auto-Increment get key and set v++

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

func (c *RedisCache) Keys(ctx context.Context, key string) ([]string, error)

Keys command

func (*RedisCache) Ping

func (c *RedisCache) Ping() error

Ping to check connection is alive

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

func (c *RedisCache) Set(ctx context.Context, key string, val interface{}, expire int64) error

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

func (c *RedisCache) SetExpire(ctx context.Context, key string, expire int64) error

SetExpire set expire time for key,expire(in seconds)

func (*RedisCache) Setup

func (c *RedisCache) Setup(conf config.IConfig) (*RedisCache, error)

Setup init cache with config

func (*RedisCache) Version

func (c *RedisCache) Version() string

Version cache version

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

func (c *RedisCache) ZRank(ctx context.Context, key, member string) (int64, error)

ZRank 返回有序集中指定成员的排名。其中有序集成员按分数值递增(从小到大)顺序排列。score 值最小的成员排名为 0

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 返回有序集中指定分数区间内的所有的成员。有序集成员按分数值递减(从大到小)的次序排列。 具有相同分数值的成员按字典序来排列

func (*RedisCache) ZRevrank

func (c *RedisCache) ZRevrank(ctx context.Context, key, member string) (int64, error)

ZRevrank 返回有序集中成员的排名。其中有序集成员按分数值递减(从大到小)排序。分数值最大的成员排名为 0 。

func (*RedisCache) ZScore

func (c *RedisCache) ZScore(ctx context.Context, key string, member string) (int64, error)

ZScore 返回有序集 key 中,成员 member 的 score 值。 如果 member 元素不是有序集 key 的成员,或 key 不存在,返回 nil 。

Jump to

Keyboard shortcuts

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