cachex

package
v0.0.0-...-5ad425f Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(ret interface{}, rds redis.Conn, cacheKey string, expire int64, bf BizFunc) error

Call 带有缓存的调用,会将业务方法结果进行缓存

func Decr

func Decr(rds redis.Conn, cacheKey string) (int64, error)

Decr 对指定的key的数值减1

func Exists

func Exists(rds redis.Conn, cacheKey string) (bool, error)

Exists 判断指定key是否存在

func Fetch

func Fetch(ret interface{}, rds redis.Conn, cacheKey string) error

Fetch 从缓存中取值

func GetBit

func GetBit(rds redis.Conn, cacheKey string, offset int64) (int, error)

GetBit 获取指定位的值

func Incr

func Incr(rds redis.Conn, cacheKey string) (int64, error)

Incr 对指定的key的数值加1

func LockCall

func LockCall(ret interface{}, rds redis.Conn, cacheKey string, expire int64, autoUnlock bool, bf BizFunc) error

LockCall 带有锁的调用,当存在并发调用可能时,先寻求获得cacheKey对应的锁,如果获取失败,则无法执行 autoUnlock - 标记是否自动释放锁(仅限请求成功时),如果不自动释放,则需要等待锁自动过期释放,此参数可以用于防止重复提交等场景

func PCall

func PCall(ret interface{}, provider Provider, cacheKey string, expire int64, bf BizFunc) error

PCall 使用provider作为redis连接提供方,并自行关闭连接,内部仍旧调用Call,其它Pxxx的方法同理

func PDecr

func PDecr(provider Provider, cacheKey string) (int64, error)

func PExists

func PExists(provider Provider, cacheKey string) (bool, error)

func PFetch

func PFetch(ret interface{}, provider Provider, cacheKey string) error

PFetch 从缓存中取值

func PGetBit

func PGetBit(provider Provider, cacheKey string, offset int64) (int, error)

func PIncr

func PIncr(provider Provider, cacheKey string) (int64, error)

func PLockCall

func PLockCall(ret interface{}, provider Provider, cacheKey string, expire int64, autoUnlock bool, bf BizFunc) error

PLockCall 带有锁的调用

func PRemove

func PRemove(provider Provider, cacheKey string)

PRemove 移除cacheKey对应的缓存

func PRemoveBatch

func PRemoveBatch(provider Provider, cacheKeys []string)

PRemoveBatch 批量数据清除

func PResetCall

func PResetCall(ret interface{}, provider Provider, cacheKey string, expire int64, bf BizFunc) error

PResetCall 重置调用,会忽略之前的缓存(先清除之前的缓存),然后在调用业务接口并缓存结果

func PSetBit

func PSetBit(provider Provider, cacheKey string, expire int64, offset int64, v int) error

func PStore

func PStore(provider Provider, cacheKey string, expire int64, data interface{}) error

PStore 直接缓存结果

func PStoreMany

func PStoreMany(provider Provider, cacheKey string, expire int64, data map[string]interface{}) error

PStoreMany 缓存多个值

func Remove

func Remove(rds redis.Conn, cacheKey string)

Remove 移除cacheKey对应的缓存

func RemoveBatch

func RemoveBatch(rds redis.Conn, cacheKeys []string)

RemoveBatch 批量数据清除

func ResetCall

func ResetCall(ret interface{}, rds redis.Conn, cacheKey string, expire int64, bf BizFunc) error

ResetCall 重置调用,会忽略之前的缓存(先清除之前的缓存),然后在调用业务接口并缓存结果

func SetBit

func SetBit(rds redis.Conn, cacheKey string, expire int64, offset int64, v int) error

SetBit 设置或清除指定偏移量上的位(bit)。位的设置或清除取决于 value,可以是 0 或者是 1 。 当expire为大于0的时候,表示需要定时过期

func SetCacheKeyPrefix

func SetCacheKeyPrefix(prefix string)

SetCacheKeyPrefix 设置缓存key的前缀

func Store

func Store(rds redis.Conn, cacheKey string, expire int64, data interface{}) error

Store 直接缓存结果

func StoreMany

func StoreMany(rds redis.Conn, cacheKey string, expire int64, data map[string]interface{}) error

StoreMany 缓存多个值

Types

type BizFunc

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

BizFunc 定义业务方法,用于在无缓存状态下获取数据

type Provider

type Provider interface {
	Redis() redis.Conn
}

Provider 定义redis数据提供对象接口

Jump to

Keyboard shortcuts

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