代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。