cache

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPrefix

func AddPrefix(key string) string

AddPrefix 添加Key前缀

func Client

func Client() interface{}

Client 获取客户端

func DecrFloat

func DecrFloat(ctx context.Context, key string, value float64) (float64, error)

DecrFloat 浮点数自减

func DecrInt

func DecrInt(ctx context.Context, key string, value int64) (int64, error)

DecrInt 整数自减

func Delete

func Delete(ctx context.Context, keys ...string) (bool, error)

Delete 删除缓存

func Has

func Has(ctx context.Context, key string) (bool, error)

Has 检测缓存是否存在

func IncrFloat

func IncrFloat(ctx context.Context, key string, value float64) (float64, error)

IncrFloat 浮点数自增

func IncrInt

func IncrInt(ctx context.Context, key string, value int64) (int64, error)

IncrInt 整数自增

func Set

func Set(ctx context.Context, key string, value interface{}, expiration ...time.Duration) error

Set 设置缓存值

func SetCache

func SetCache(cache Cache)

SetCache 设置缓存

Types

type Cache

type Cache interface {
	// Has 检测缓存是否存在
	Has(ctx context.Context, key string) (bool, error)
	// Get 获取缓存值
	Get(ctx context.Context, key string, def ...interface{}) Result
	// Set 设置缓存值
	Set(ctx context.Context, key string, value interface{}, expiration ...time.Duration) error
	// GetSet 获取设置缓存值
	GetSet(ctx context.Context, key string, fn SetValueFunc) Result
	// Delete 删除缓存
	Delete(ctx context.Context, keys ...string) (bool, error)
	// IncrInt 整数自增
	IncrInt(ctx context.Context, key string, value int64) (int64, error)
	// IncrFloat 浮点数自增
	IncrFloat(ctx context.Context, key string, value float64) (float64, error)
	// DecrInt 整数自减
	DecrInt(ctx context.Context, key string, value int64) (int64, error)
	// DecrFloat 浮点数自减
	DecrFloat(ctx context.Context, key string, value float64) (float64, error)
	// AddPrefix 添加Key前缀
	AddPrefix(key string) string
	// Client 获取客户端
	Client() interface{}
}

func GetCache

func GetCache() Cache

GetCache 获取缓存

type Result

type Result interface {
	Err() error
	Result() (value.Value, error)
	Int() (int, error)
	Int8() (int8, error)
	Int16() (int16, error)
	Int32() (int32, error)
	Int64() (int64, error)
	Uint() (uint, error)
	Uint8() (uint8, error)
	Uint16() (uint16, error)
	Uint32() (uint32, error)
	Uint64() (uint64, error)
	Float32() (float32, error)
	Float64() (float64, error)
	Bool() (bool, error)
	String() (string, error)
	Duration() (time.Duration, error)
	Ints() ([]int, error)
	Int8s() ([]int8, error)
	Int16s() ([]int16, error)
	Int32s() ([]int32, error)
	Int64s() ([]int64, error)
	Uints() ([]uint, error)
	Uint8s() ([]uint8, error)
	Uint16s() ([]uint16, error)
	Uint32s() ([]uint32, error)
	Uint64s() ([]uint64, error)
	Float32s() ([]float32, error)
	Float64s() ([]float64, error)
	Bools() ([]bool, error)
	Strings() ([]string, error)
	Bytes() ([]byte, error)
	Durations() ([]time.Duration, error)
	Slice() ([]interface{}, error)
	Map() (map[string]interface{}, error)
	Scan(pointer interface{}) error
}

func Get

func Get(ctx context.Context, key string, def ...interface{}) Result

Get 获取缓存值

func GetSet

func GetSet(ctx context.Context, key string, fn SetValueFunc) Result

GetSet 获取设置缓存值

func NewResult

func NewResult(val interface{}, err ...error) Result

type SetValueFunc

type SetValueFunc func() (interface{}, error)

Jump to

Keyboard shortcuts

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