|
@@ -0,0 +1,112 @@
|
|
|
+```GO
|
|
|
+package redis_util // import "app.yhyue.com/BP/redis_util"
|
|
|
+
|
|
|
+* redis_util Redis工具包<br/> 作者:hongbo<br/> 日期:2020-4-22<br/>
|
|
|
+
|
|
|
+VARIABLES
|
|
|
+
|
|
|
+var RedisLoginPool *redisLogin.Pool
|
|
|
+ RedisLoginPool 用于登陆的Redis连接池
|
|
|
+
|
|
|
+var RedisPool map[string]*redigo.Pool
|
|
|
+ RedisPool redis 多服务端连接池,1个应用同时连接多个redis服务
|
|
|
+
|
|
|
+
|
|
|
+FUNCTIONS
|
|
|
+
|
|
|
+func BulkPut(code string, timeout int, obj ...interface{}) bool
|
|
|
+ 批量存储KV对,可指定超时时间,obj格式=[[key,value],,,]
|
|
|
+
|
|
|
+func Decrby(code, key string, val int) int64
|
|
|
+ 指定key,自减计数,并返回增加后的值
|
|
|
+
|
|
|
+func Del(code string, key ...interface{}) bool
|
|
|
+ 批量删除多个key NOTE: key 为变参
|
|
|
+
|
|
|
+func DelByCodePattern(code, key string)
|
|
|
+ 根据key前辍,批量删除 NOTE: key前缀 如:key*
|
|
|
+
|
|
|
+func Exists(code, key string) (bool, error)
|
|
|
+ 判断一个key是否存在
|
|
|
+
|
|
|
+func FlushDB(code string) bool
|
|
|
+ 删所有key,清理Redis库
|
|
|
+
|
|
|
+func Get(code, key string) (result interface{})
|
|
|
+ 依据Key,获取字符串,返回interface{},需要自己断言
|
|
|
+
|
|
|
+func GetBytes(code, key string) (ret *[]byte, err error)
|
|
|
+ 依据Key,获取字节数组
|
|
|
+
|
|
|
+func GetInt(code, key string) int
|
|
|
+ 依据Key,获取Value 自动转化为int格式
|
|
|
+
|
|
|
+func GetInterface(code, key string, result interface{})
|
|
|
+ NOTE: 建议使用GetNewInterface 依据Key,获取字符串,返回interface{} 为兼容老代码所写
|
|
|
+
|
|
|
+func GetKeysByPattern(code, key string) []interface{}
|
|
|
+ 根据正则key,获取结果
|
|
|
+
|
|
|
+func GetLoginVal(key string, wxFunc func(wxParams []string) bool)
|
|
|
+ GetLoginVal 获取置Key,并透传到入参处理函数 用于登陆的Redis
|
|
|
+
|
|
|
+func GetNewBytes(code, key string) (ret *[]byte, err error)
|
|
|
+ FIXME: 写注释,表示很忧伤,GetNewBytes/GetBytes的实现,没看出来差异啊 依据Key,获取字节数组
|
|
|
+
|
|
|
+func GetNewInt(code, key string) (int, error)
|
|
|
+ 依据Key,获取Value 兼容int类型数据将自动转换
|
|
|
+
|
|
|
+func GetNewInterface(code, key string, result interface{}) error
|
|
|
+ NOTE:注意result必须为指针对象 依据Key,获取字符串,返回interface{} ,基础方法,部分外部接口依赖此方法
|
|
|
+
|
|
|
+func GetStr(code, key string) string
|
|
|
+ 依据Key,获取Value 自动转化为字符串格式
|
|
|
+
|
|
|
+func Incr(code, key string) int64
|
|
|
+ 指定key,自增计数,并返回增加后的值
|
|
|
+
|
|
|
+func InitRedis(addrs string)
|
|
|
+ 初始化redis 多端连接池 <br/> @param addrs
|
|
|
+ enterprise=192.168.3.14:1379,service=192.168.3.14:2379,other=192.168.3.14:3379
|
|
|
+
|
|
|
+func InitRedisBySize(addrs string, maxSize, maxIdle, timeout int)
|
|
|
+ 初始化redis连接池,支持多个redis库
|
|
|
+
|
|
|
+func InitRedisLogin(addrs string)
|
|
|
+ InitRedisLogin 初始化用于登陆的Redis连接池
|
|
|
+
|
|
|
+func LLEN(code, list string) int64
|
|
|
+ List数据长度
|
|
|
+
|
|
|
+func LPOP(code, list string) (result interface{})
|
|
|
+ List数据 KV,队首出栈操作,对应RPOP队尾出栈
|
|
|
+
|
|
|
+func Mget(code string, key []string) []interface{}
|
|
|
+ 批量取多个key的值
|
|
|
+
|
|
|
+func Pop(code string, key string) (result interface{})
|
|
|
+ 常规KV,出栈操作,查询指定Key,返回Value后,删除此KV对
|
|
|
+
|
|
|
+func Put(code, key string, obj interface{}, timeout int) bool
|
|
|
+ 存储KV对,可设置超时时间,单位秒
|
|
|
+
|
|
|
+func PutBytes(code, key string, data *[]byte, timeout int) (err error)
|
|
|
+ 存储KV对,Value是字节数组,可指定超时时间
|
|
|
+
|
|
|
+func PutCKV(code, key string, obj interface{}) bool
|
|
|
+ 存储KV对,并设置永不超时
|
|
|
+
|
|
|
+func PutKV(key string, obj interface{}) bool
|
|
|
+ 分流redis ,并存入字符串缓存
|
|
|
+
|
|
|
+func RPUSH(code, list string, val interface{}) bool
|
|
|
+ List数据 后端入栈,在List末尾追加数据 对应LPUSH在队首插入数据
|
|
|
+
|
|
|
+func SetExpire(code, key string, expire int) error
|
|
|
+ 设置超时时间,单位秒
|
|
|
+
|
|
|
+func SetLoginVal(key, value string)
|
|
|
+ SetLoginVal 设置K,V值 用于登陆的Redis
|
|
|
+
|
|
|
+func catch()
|
|
|
+```
|