goredis

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2022 License: MulanPSL-2.0 Imports: 8 Imported by: 0

Documentation

Index

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{}
}

func WithExpire

func WithExpire(t time.Duration) *OperationAttr

设置过期时间

type OperationAttrs

type OperationAttrs []*OperationAttr

func (OperationAttrs) Find

func (this OperationAttrs) Find(name string) *InterfaceResult

查找是否有该属性

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) Del

func (this *SimpleCache) Del(key string)

删除缓存

func (*SimpleCache) GetCache

func (this *SimpleCache) GetCache(key string) (ret interface{})

获取缓存

func (*SimpleCache) Lock

func (this *SimpleCache) Lock(key string, exp time.Duration) bool

/锁

func (*SimpleCache) SetCache

func (this *SimpleCache) SetCache(key string, value interface{})

设置缓存

func (*SimpleCache) Unlock

func (this *SimpleCache) Unlock(key string)

解锁

type StringOperation

type StringOperation struct {
	mstruct.MCacheConfig
	// contains filtered or unexported fields
}

func NewStringOperation

func NewStringOperation(config mstruct.MCacheConfig) *StringOperation

func (*StringOperation) Del

func (this *StringOperation) Del(key string)

删除缓存

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

type StringResult struct {
	Result string
	Err    error
}

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{}

如果获取不到缓存,则执行默认方法

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL