1 Star 0 Fork 0

masaichi / mredis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mredis.go 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
masaichi 提交于 2022-11-30 00:18 . 更改包名
package mredis
import (
"gitee.com/masaichi/mredis/lib"
"gitee.com/masaichi/mredis/mstruct"
"time"
)
type MRedis struct {
mstruct.MCacheConfig
LockExpire time.Duration
}
//设置连接
func (this *MRedis) SetConn(host string, port int, pwd string, db int) {
mconfig := mstruct.MCacheConfig{
Host: host,
Port: port,
Password: pwd,
DB: db,
}
this.MCacheConfig = mconfig
pool := lib.NewMCachePool(mconfig)
pool.SetConn()
}
//实例化一个操作对象
func NewMRedis() *MRedis {
return &MRedis{LockExpire: time.Second * 30} //设置默认锁时间为30s
}
//获取缓存
func (this *MRedis) GetCache(key string) interface{} {
return lib.NewMCache().GetCache(key)
}
//设置缓存
func (this *MRedis) SetCache(key string, val interface{}) {
lib.NewMCache().SetCache(key, val)
}
//锁
func (this *MRedis) Lock(key string) bool {
return lib.NewMCache().Lock(key, this.LockExpire)
}
//解锁
func (this *MRedis) Unlock(key string) {
lib.NewMCache().Unlock(key)
}
//删除缓存
func (this *MRedis) Del(key string) {
lib.NewMCache().Unlock(key)
}
1
https://gitee.com/masaichi/mredis.git
git@gitee.com:masaichi/mredis.git
masaichi
mredis
mredis
v0.0.2

搜索帮助