Redis

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ATTR_EXPIRE = "expr" //过期时间
	ATTR_NX     = "nx"   // setnx
	ATTR_XX     = "xx"   // setxx
)
View Source
const (
	Serilizer_JSON = "json"
	Serilizer_GOB  = "gob"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CachePolicy

type CachePolicy interface {
	Before(key string)                      //之前执行
	IfNil(key string, v interface{})        //当空值是操作
	SetOperation(opt *RedisStringOperation) //设置处理器 目前支持string
}

type CrossPolicy

type CrossPolicy struct {
	KeyRegx string        //检查key的正则
	Expire  time.Duration //可以配置查找失败过期时间
	// contains filtered or unexported fields
}

缓存穿透 策略

func NewCrossPolicy

func NewCrossPolicy(keyRegx string, expire time.Duration) *CrossPolicy

func (*CrossPolicy) Before

func (this *CrossPolicy) Before(key string)

func (*CrossPolicy) IfNil

func (this *CrossPolicy) IfNil(key string, v interface{})

func (*CrossPolicy) SetOperation

func (this *CrossPolicy) SetOperation(opt *RedisStringOperation)

type DBGetterFunc

type DBGetterFunc func() interface{}

简单缓存

type OperationAttr

type OperationAttr struct {
	Name  string
	Value interface{}
}

属性

func WithExpire

func WithExpire(t time.Duration) *OperationAttr

func WithNX

func WithNX() *OperationAttr

func WithXX

func WithXX() *OperationAttr

type OperationAttrs

type OperationAttrs []*OperationAttr

func (OperationAttrs) Find

func (this OperationAttrs) Find(name string) *Result.ErrorResult

type RedisStringOperation

type RedisStringOperation struct {
	Ctx   context.Context
	Redis *redis.Client `inject:"-"`
}

专门处理string类型的操作

func NewStringOperation

func NewStringOperation() *RedisStringOperation

func (*RedisStringOperation) Get

func (*RedisStringOperation) MGet

func (this *RedisStringOperation) MGet(keys ...string) *Result.ErrorResult

func (*RedisStringOperation) Name

func (this *RedisStringOperation) Name() string

func (*RedisStringOperation) Set

func (this *RedisStringOperation) Set(key string, value interface{},
	attrs ...*OperationAttr) *Result.ErrorResult

type SimpleCache

type SimpleCache struct {
	Operation *RedisStringOperation //操作类
	Expire    time.Duration         // 过期时间
	DBGetter  DBGetterFunc          // 一旦缓存中没有  DB获取的方法
	Serilizer string                // 序列化方式
	Policy    CachePolicy           //验证策略
}

func NewSimpleCache

func NewSimpleCache(operation *RedisStringOperation, expire time.Duration, serilizer string) *SimpleCache

func (*SimpleCache) GetCache

func (this *SimpleCache) GetCache(key string) (ret Result.Any)

func (*SimpleCache) GetCacheForObject

func (this *SimpleCache) GetCacheForObject(key string, obj interface{}) (ret Result.Any)

func (*SimpleCache) SetCache

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

设置缓存

func (*SimpleCache) SetCahPolicy

func (this *SimpleCache) SetCahPolicy(policy CachePolicy)

Jump to

Keyboard shortcuts

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