Documentation ¶
Index ¶
- Constants
- type Redis
- func (r *Redis) Append(ctx *gin.Context, key string, value interface{}) (int, error)
- func (r *Redis) BLPop(ctx *gin.Context, key string, timeout int64) ([][]byte, error)
- func (r *Redis) BRPop(ctx *gin.Context, key string, timeout int64) ([][]byte, error)
- func (r *Redis) BRPopLPush(ctx *gin.Context, sourceKey string, destKey string, timeout int64) ([][]byte, error)
- func (r *Redis) Close()
- func (r *Redis) Decr(ctx *gin.Context, key string) (int64, error)
- func (r *Redis) DecrBy(ctx *gin.Context, key string, value int64) (int64, error)
- func (r *Redis) Del(ctx *gin.Context, keys ...interface{}) (int64, error)
- func (r *Redis) Do(ctx *gin.Context, commandName string, args ...interface{}) (reply interface{}, err error)
- func (r *Redis) Exists(ctx *gin.Context, key string) (bool, error)
- func (r *Redis) Expire(ctx *gin.Context, key string, time int64) (bool, error)
- func (r *Redis) Get(ctx *gin.Context, key string) ([]byte, error)
- func (r *Redis) HDel(ctx *gin.Context, key string, fields ...string) (int64, error)
- func (r *Redis) HExists(ctx *gin.Context, key string, field string) (bool, error)
- func (r *Redis) HGet(ctx *gin.Context, key, field string) ([]byte, error)
- func (r *Redis) HGetAll(ctx *gin.Context, key string) ([][]byte, error)
- func (r *Redis) HIncrBy(ctx *gin.Context, key, field string, value int64) (int64, error)
- func (r *Redis) HKeys(ctx *gin.Context, key string) ([][]byte, error)
- func (r *Redis) HLen(ctx *gin.Context, key string) (int64, error)
- func (r *Redis) HMGet(ctx *gin.Context, key string, fields ...string) ([][]byte, error)
- func (r *Redis) HMSet(ctx *gin.Context, key string, kv map[string]interface{}) error
- func (r *Redis) HScan(ctx *gin.Context, key string, cursor uint64, pattern string, count int) (uint64, map[string][]byte, error)
- func (r *Redis) HSet(ctx *gin.Context, key, field string, val interface{}) (int, error)
- func (r *Redis) HVals(ctx *gin.Context, key string) ([][]byte, error)
- func (r *Redis) Incr(ctx *gin.Context, key string) (int64, error)
- func (r *Redis) IncrBy(ctx *gin.Context, key string, value int64) (int64, error)
- func (r *Redis) IncrByFloat(ctx *gin.Context, key string, value float64) (float64, error)
- func (r *Redis) LIndex(ctx *gin.Context, key string, index int) ([]byte, error)
- func (r *Redis) LInsert(ctx *gin.Context, key string, before bool, pivot interface{}, ...) (int, error)
- func (r *Redis) LLen(ctx *gin.Context, key string) (int, error)
- func (r *Redis) LPop(ctx *gin.Context, key string) ([]byte, error)
- func (r *Redis) LPush(ctx *gin.Context, key string, members ...interface{}) (int, error)
- func (r *Redis) LPushX(ctx *gin.Context, key string, member interface{}) (int, error)
- func (r *Redis) LRange(ctx *gin.Context, key string, start int, stop int) ([][]byte, error)
- func (r *Redis) LRem(ctx *gin.Context, key string, count int, value interface{}) (int, error)
- func (r *Redis) LSet(ctx *gin.Context, key string, index int, value interface{}) (bool, error)
- func (r *Redis) LTrim(ctx *gin.Context, key string, start int, stop int) (bool, error)
- func (r *Redis) Lua(ctx *gin.Context, script string, keyCount int, keysAndArgs ...interface{}) (interface{}, error)
- func (r *Redis) MGet(ctx *gin.Context, keys ...string) [][]byte
- func (r *Redis) MSet(ctx *gin.Context, values ...interface{}) error
- func (r *Redis) PTtl(ctx *gin.Context, key string) (int64, error)
- func (r *Redis) RPop(ctx *gin.Context, key string) ([]byte, error)
- func (r *Redis) RPopLPush(ctx *gin.Context, sourceKey string, destKey string) ([]byte, error)
- func (r *Redis) RPush(ctx *gin.Context, key string, members ...interface{}) (int, error)
- func (r *Redis) RPushX(ctx *gin.Context, key string, member interface{}) (int, error)
- func (r *Redis) SAdd(ctx *gin.Context, key string, members ...string) (int64, error)
- func (r *Redis) SCard(ctx *gin.Context, key string) (int64, error)
- func (r *Redis) SDiff(ctx *gin.Context, keys ...string) ([][]byte, error)
- func (r *Redis) SDiffStore(ctx *gin.Context, dstKey string, keys ...string) (int64, error)
- func (r *Redis) SInter(ctx *gin.Context, keys ...string) ([][]byte, error)
- func (r *Redis) SInterStore(ctx *gin.Context, dstKey string, keys ...string) (int64, error)
- func (r *Redis) SIsMember(ctx *gin.Context, key string, member string) (bool, error)
- func (r *Redis) SMembers(ctx *gin.Context, key string) ([][]byte, error)
- func (r *Redis) SMove(ctx *gin.Context, source, destination, member string) (bool, error)
- func (r *Redis) SPop(ctx *gin.Context, key string) ([]byte, error)
- func (r *Redis) SRandMember(ctx *gin.Context, key string) ([]byte, error)
- func (r *Redis) SRandMemberCount(ctx *gin.Context, key string, count int) ([][]byte, error)
- func (r *Redis) SRem(ctx *gin.Context, key string, members ...string) (int64, error)
- func (r *Redis) SScan(ctx *gin.Context, key string, cursor uint64, pattern string, count int) (uint64, []string, error)
- func (r *Redis) SUnion(ctx *gin.Context, keys ...string) ([][]byte, error)
- func (r *Redis) SUnionStore(ctx *gin.Context, dstKey string, keys ...string) (int64, error)
- func (r *Redis) Set(ctx *gin.Context, key string, value interface{}, expire ...int64) error
- func (r *Redis) SetEx(ctx *gin.Context, key string, value interface{}, expire int64) error
- func (r *Redis) SetNxByEX(ctx *gin.Context, key string, value interface{}, expire uint64) (bool, error)
- func (r *Redis) SetNxByPX(ctx *gin.Context, key string, value interface{}, expire uint64) (bool, error)
- func (r *Redis) Ttl(ctx *gin.Context, key string) (int64, error)
- func (r *Redis) ZAdd(ctx *gin.Context, key string, maps map[string]float64) (int64, error)
- func (r *Redis) ZCard(ctx *gin.Context, key string) (int64, error)
- func (r *Redis) ZCount(ctx *gin.Context, key, min, max string) (int64, error)
- func (r *Redis) ZIncrBy(ctx *gin.Context, key string, delta float64, member string) (float64, error)
- func (r *Redis) ZInterStore(ctx *gin.Context, destination string, keys []string, weights []int, ...) (int64, error)
- func (r *Redis) ZLexCount(ctx *gin.Context, key, min, max string) (int64, error)
- func (r *Redis) ZRange(ctx *gin.Context, key string, start int, stop int, withscores bool) ([][]byte, error)
- func (r *Redis) ZRangeByScore(ctx *gin.Context, key, min, max string, withscores, limit bool, offset int, ...) ([][]byte, error)
- func (r *Redis) ZRank(ctx *gin.Context, key string, member string) (int64, error)
- func (r *Redis) ZRem(ctx *gin.Context, key string, members ...string) (int64, error)
- func (r *Redis) ZRemRangeByLex(ctx *gin.Context, key, min, max string) (int64, error)
- func (r *Redis) ZRemRangeByRank(ctx *gin.Context, key string, start int, stop int) (int64, error)
- func (r *Redis) ZRemRangeByScore(ctx *gin.Context, key, min, max string) (int64, error)
- func (r *Redis) ZRevRange(ctx *gin.Context, key string, start int, stop int, withscores bool) ([][]byte, error)
- func (r *Redis) ZRevRangeByScore(ctx *gin.Context, key, min, max string, withscores, limit bool, offset int, ...) ([][]byte, error)
- func (r *Redis) ZRevRank(ctx *gin.Context, key string, member string) (int64, error)
- func (r *Redis) ZScan(ctx *gin.Context, key string, cursor uint64, pattern string, count int) (uint64, []string, error)
- func (r *Redis) ZScore(ctx *gin.Context, key string, member string) (string, error)
- func (r *Redis) ZUnionStore(ctx *gin.Context, destination string, keys []string, weights []int, ...) (int64, error)
- type RedisConf
Constants ¶
const ( ExSeconds = "EX" PxMillisSeconds = "PX" NotExists = "NX" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
func InitRedisClient ¶
func (*Redis) BLPop ¶
当给定列表内没有任何元素可供弹出的时候,连接将被 BLPOP 命令阻塞,直到等待超时或发现可弹出元素为止。 timout单位为:秒 设置为0表示阻塞时间无限期延长 return: 一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值
func (*Redis) BRPop ¶
当给定列表内没有任何元素可供弹出的时候,连接将被 BRPOP 命令阻塞,直到等待超时或发现可弹出元素为止。 timout单位为:秒 设置为0表示阻塞时间无限期延长 return: 一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值
func (*Redis) BRPopLPush ¶
func (r *Redis) BRPopLPush(ctx *gin.Context, sourceKey string, destKey string, timeout int64) ([][]byte, error)
timeout单位为:秒 设置为0表示阻塞时间无限期延长
func (*Redis) HScan ¶
func (r *Redis) HScan(ctx *gin.Context, key string, cursor uint64, pattern string, count int) (uint64, map[string][]byte, error)
基于游标的迭代器,每次被调用会返回新的游标,在下次迭代时,需要使用这个新游标作为游标参数,以此来延续之前的迭代过程 param: key param: cursor 游标 传""表示开始新迭代 param: count 每次迭代返回元素的最大值,limit hint,实际数量并不准确=count param: pattern 模式参数,符合glob风格 ? (一个字符) * (任意个字符) [] (匹配其中的任意一个字符) \x (转义字符) return: 新的cursor,filed-value map 当返回"",空map时,表示迭代已结束
func (*Redis) IncrByFloat ¶
func (*Redis) LInsert ¶
func (r *Redis) LInsert(ctx *gin.Context, key string, before bool, pivot interface{}, value interface{}) (int, error)
将值 value 插入到列表 key 当中,位于值 pivot 之前或之后
func (*Redis) LRem ¶
根据参数 count 的值,移除列表中与参数 value 相等的元素 count 的值可以是以下几种:
count > 0 : 从表头开始向表尾搜索,移除与 value 相等的元素,数量为 count 。 count < 0 : 从表尾开始向表头搜索,移除与 value 相等的元素,数量为 count 的绝对值。 count = 0 : 移除表中所有与 value 相等的值。
return: 被移除元素的数量
func (*Redis) RPopLPush ¶
将列表 source 中的最后一个元素(尾元素)弹出,并返回 将 source 弹出的元素插入到列表 destination ,作为 destination 列表的的头元素。
func (*Redis) SAdd ¶
将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略 return: 被添加到集合中的新元素的数量,不包括被忽略的元素
func (*Redis) SDiffStore ¶
这个命令的作用和 SDIFF key [key …] 类似,但它将结果保存到 destination 集合,而不是简单地返回结果集
func (*Redis) SInterStore ¶
这个命令类似于 SINTER key [key …] 命令,但它将结果保存到 destination 集合,而不是简单地返回结果集
func (*Redis) SRandMember ¶
如果命令执行时,只提供了 key 参数,那么返回集合中的一个随机元素
func (*Redis) SRandMemberCount ¶
func (*Redis) SScan ¶
func (r *Redis) SScan(ctx *gin.Context, key string, cursor uint64, pattern string, count int) (uint64, []string, error)
基于游标的迭代器,每次被调用会返回新的游标,在下次迭代时,需要使用这个新游标作为游标参数,以此来延续之前的迭代过程 param: key param: cursor 游标 传""表示开始新迭代 param: count 每次迭代返回元素的最大值,limit hint,实际数量并不准确=count param: pattern 模式参数,符合glob风格 ? (一个字符) * (任意个字符) [] (匹配其中的任意一个字符) \x (转义字符) return: 新的cursor,value[] 当返回"",空切片时,表示迭代已结束
func (*Redis) SUnionStore ¶
这个命令类似于 SUNION key [key …] 命令,但它将结果保存到 destination 集合,而不是简单地返回结果集
func (*Redis) SetNxByEX ¶
func (r *Redis) SetNxByEX(ctx *gin.Context, key string, value interface{}, expire uint64) (bool, error)
SetNxByEX 设置过期时间为秒级的redis分布式锁
func (*Redis) SetNxByPX ¶
func (r *Redis) SetNxByPX(ctx *gin.Context, key string, value interface{}, expire uint64) (bool, error)
SetNxByPX 设置过期时间为毫秒的redis分布式锁
func (*Redis) ZAdd ¶
将一个或多个 member 元素加入到有序集 key 当中,已经存在于集合的 member 元素将更新该元素的 score 值 param: maps Member-Score集合 return: 被添加到集合中的新元素的数量,不包括被更新的、已存在的元素
func (*Redis) ZIncrBy ¶
func (r *Redis) ZIncrBy(ctx *gin.Context, key string, delta float64, member string) (float64, error)
为有序集 key 的成员 member 的 score 值加上增量 delta
func (*Redis) ZInterStore ¶
func (r *Redis) ZInterStore(ctx *gin.Context, destination string, keys []string, weights []int, aggregate string) (int64, error)
计算给定的一个或多个有序集的交集,其中给定 key 的数量必须以 numkeys 参数指定,并将该交集(结果集)储存到 destination 。
func (*Redis) ZRange ¶
func (r *Redis) ZRange(ctx *gin.Context, key string, start int, stop int, withscores bool) ([][]byte, error)
返回有序集 key 中,指定区间内的成员。其中成员的位置按 score 值递增(从小到大)来排序 withscores指定是否返回得分 return: Score-Member集合
func (*Redis) ZRangeByScore ¶
func (r *Redis) ZRangeByScore(ctx *gin.Context, key, min, max string, withscores, limit bool, offset int, count int) ([][]byte, error)
返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。 有序集成员按 score 值递增(从小到大)次序排列。 withscores指定是否返回得分 limit 是否分页方法,false返回所有的数据
func (*Redis) ZRank ¶
返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递增(从小到大)顺序排列。 排名以 0 为底,也就是说, score 值最小的成员排名为 0 。
func (*Redis) ZRemRangeByLex ¶
对于一个所有成员的分值都相同的有序集合键 key 来说, 这个命令会移除该集合中, 成员介于 min 和 max 范围内的所有元素。 如:"key", "-inf", "(2"
func (*Redis) ZRemRangeByRank ¶
移除有序集 key 中,指定排名(rank)区间内的所有成员。 区间分别以下标参数 start 和 stop 指出,包含 start 和 stop 在内。 return: 被移除成员的数量
func (*Redis) ZRemRangeByScore ¶
移除有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。 如:"key", "-inf", "(2" return: 被移除成员的数量
func (*Redis) ZRevRange ¶
func (r *Redis) ZRevRange(ctx *gin.Context, key string, start int, stop int, withscores bool) ([][]byte, error)
返回有序集 key 中,指定区间内的成员。其中成员的位置按 score 值递增(从大到小)来排序 return: Score-Member集合
func (*Redis) ZRevRangeByScore ¶
func (r *Redis) ZRevRangeByScore(ctx *gin.Context, key, min, max string, withscores, limit bool, offset int, count int) ([][]byte, error)
返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。有序集成员按 score 值递增(从大到小)次序排列。 如:"key", "-inf", "(2"
func (*Redis) ZRevRank ¶
返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递增(从大到小)顺序排列。 排名以 0 为底,也就是说, score 值最小的成员排名为 0 。
func (*Redis) ZScan ¶
func (r *Redis) ZScan(ctx *gin.Context, key string, cursor uint64, pattern string, count int) (uint64, []string, error)
基于游标的迭代器,每次被调用会返回新的游标,在下次迭代时,需要使用这个新游标作为游标参数,以此来延续之前的迭代过程 param: key param: cursor 游标 传""表示开始新迭代 param: count 每次迭代返回元素的最大值,limit hint,实际数量并不准确=count param: pattern 模式参数,符合glob风格 ? (一个字符) * (任意个字符) [] (匹配其中的任意一个字符) \x (转义字符) return: 新的cursor,score-member pair 当返回"",空map时,表示迭代已结束
func (*Redis) ZUnionStore ¶
func (r *Redis) ZUnionStore(ctx *gin.Context, destination string, keys []string, weights []int, aggregate string) (int64, error)
ZUnionStore destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] 计算给定的一个或多个有序集的并集,其中给定 key 的数量必须以 numkeys 参数指定,并将该并集(结果集)储存到 destination 。
type RedisConf ¶
type RedisConf struct { Enable bool `yaml:"enable" json:"enable" mapstructure:"enable"` Addr string `yaml:"addr" json:"addr" mapstructure:"addr"` Password string `yaml:"password" json:"password" mapstructure:"password"` MaxIdle int `yaml:"maxIdle" json:"maxIdle" mapstructure:"maxIdle"` MaxActive int `yaml:"maxActive" json:"maxActive" mapstructure:"maxActive"` IdleTimeout time.Duration `yaml:"idleTimeout" json:"idleTimeout" mapstructure:"idleTimeout"` MaxConnLifetime time.Duration `yaml:"maxConnLifetime" json:"maxConnLifetime" mapstructure:"maxConnLifetime"` ConnTimeOut time.Duration `yaml:"connTimeOut" json:"connTimeOut" mapstructure:"connTimeOut"` ReadTimeOut time.Duration `yaml:"readTimeOut" json:"readTimeOut" mapstructure:"readTimeOut"` WriteTimeOut time.Duration `yaml:"writeTimeOut" json:"writeTimeOut" mapstructure:"writeTimeOut"` ShowLog bool `yaml:"showLog" json:"showLog" mapstructure:"showLog"` }