Documentation ¶
Index ¶
- Constants
- func Redis(config mstruct.MCacheConfig) *redis.Client
- type DBGettFunc
- type InterfaceResult
- type OperationAttr
- type OperationAttrs
- type SimpleCache
- type StringOperation
- func (this *StringOperation) Del(key string)
- func (this *StringOperation) Get(key string) *StringResult
- func (this *StringOperation) Set(key string, value interface{}, attrs ...*OperationAttr) *InterfaceResult
- func (this *StringOperation) SetNx(key string, value interface{}, attrs ...*OperationAttr) *InterfaceResult
- func (this *StringOperation) SetXx(key string, value interface{}, attrs ...*OperationAttr) *InterfaceResult
- type StringResult
Constants ¶
View Source
const ATTR_EXPIRE = "expire"
View Source
const (
Serilizer_JSON = "json"
)
Variables ¶
This section is empty.
Functions ¶
func Redis ¶
func Redis(config mstruct.MCacheConfig) *redis.Client
Types ¶
type DBGettFunc ¶
type DBGettFunc func() interface{}
type InterfaceResult ¶
type InterfaceResult struct { Result interface{} Err error }
为什么要这个类,是因为redis方法的返回值不一样,有些是string,error, 有些是 bool, error,这个结构体兼容到了,对返回结果进行统一封装
func NewInterfaceResult ¶
func NewInterfaceResult(result interface{}, err error) *InterfaceResult
func (*InterfaceResult) UnWrap ¶
func (this *InterfaceResult) UnWrap() interface{}
func (*InterfaceResult) UnWrapDefault ¶
func (this *InterfaceResult) UnWrapDefault(def interface{}) interface{}
type OperationAttr ¶
type OperationAttr struct { Name string Value interface{} }
type OperationAttrs ¶
type OperationAttrs []*OperationAttr
type SimpleCache ¶
type SimpleCache struct { Operation *StringOperation Expire time.Duration DBGeter DBGettFunc Serilizer string }
func NewSimpleCache ¶
func NewSimpleCache(operation *StringOperation, expire time.Duration, serilizer string) *SimpleCache
func (*SimpleCache) SetCache ¶
func (this *SimpleCache) SetCache(key string, value interface{})
设置缓存
type StringOperation ¶
type StringOperation struct { mstruct.MCacheConfig // contains filtered or unexported fields }
func NewStringOperation ¶
func NewStringOperation(config mstruct.MCacheConfig) *StringOperation
func (*StringOperation) Get ¶
func (this *StringOperation) Get(key string) *StringResult
func (*StringOperation) Set ¶
func (this *StringOperation) Set(key string, value interface{}, attrs ...*OperationAttr) *InterfaceResult
func (*StringOperation) SetNx ¶
func (this *StringOperation) SetNx(key string, value interface{}, attrs ...*OperationAttr) *InterfaceResult
func (*StringOperation) SetXx ¶
func (this *StringOperation) SetXx(key string, value interface{}, attrs ...*OperationAttr) *InterfaceResult
如果有值,则执行,常用于开关业务,比如新闻缓存,有key的走缓存逻辑 标记业务数据,多个步骤删除数据,第一步 软删除 第二步 如果setxx为true,则数据库删除
type StringResult ¶
func NewStringResult ¶
func NewStringResult(result string, err error) *StringResult
func (*StringResult) Unwrap ¶
func (this *StringResult) Unwrap() string
func (*StringResult) UnwrapDefault ¶
func (this *StringResult) UnwrapDefault(def string) string
func (*StringResult) UnwrapElse ¶
func (this *StringResult) UnwrapElse(f func() string) interface{}
如果获取不到缓存,则执行默认方法
Click to show internal directories.
Click to hide internal directories.