代码拉取完成,页面将自动刷新
package goredis
import (
"context"
"gitee.com/masaichi/mastool/masredis/mstruct"
"time"
)
type StringOperation struct {
ctx context.Context
mstruct.MCacheConfig
}
func NewStringOperation(config mstruct.MCacheConfig) *StringOperation {
return &StringOperation{ctx: context.Background(), MCacheConfig: config}
}
func (this *StringOperation) Set(key string, value interface{}, attrs ...*OperationAttr) *InterfaceResult {
exp := OperationAttrs(attrs).Find(ATTR_EXPIRE).UnWrapDefault(time.Second * 0).(time.Duration)
return NewInterfaceResult(Redis(this.MCacheConfig).Set(this.ctx, key, value, exp).Result())
}
func (this *StringOperation) SetNx(key string, value interface{}, attrs ...*OperationAttr) *InterfaceResult {
exp := OperationAttrs(attrs).Find(ATTR_EXPIRE).UnWrapDefault(time.Second * 0).(time.Duration)
return NewInterfaceResult(Redis(this.MCacheConfig).SetNX(this.ctx, key, value, exp).Result())
}
// 如果有值,则执行,常用于开关业务,比如新闻缓存,有key的走缓存逻辑
// 标记业务数据,多个步骤删除数据,第一步 软删除 第二步 如果setxx为true,则数据库删除
func (this *StringOperation) SetXx(key string, value interface{}, attrs ...*OperationAttr) *InterfaceResult {
exp := OperationAttrs(attrs).Find(ATTR_EXPIRE).UnWrapDefault(time.Second * 0).(time.Duration)
return NewInterfaceResult(Redis(this.MCacheConfig).SetXX(this.ctx, key, value, exp).Result())
}
func (this *StringOperation) Get(key string) *StringResult {
return NewStringResult(Redis(this.MCacheConfig).Get(this.ctx, key).Result())
}
// 删除缓存
func (this *StringOperation) Del(key string) {
Redis(this.MCacheConfig).Del(this.ctx, key)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。