cache

package
v1.0.136 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SpinLocker

func SpinLocker(lockObj, errorMsg string, trySecond, expSecond int, callObj func() error) error

func TryLocker

func TryLocker(lockObj, errorMsg string, expSecond int, callObj func() error) error

Types

type Cache

type Cache interface {
	// 查询
	Get(key string, input interface{}) (interface{}, bool, error)
	GetInt64(key string) (int64, error)
	GetFloat64(key string) (float64, error)
	GetString(key string) (string, error)
	GetBool(key string) (bool, error)
	// 保存/过期时间(秒)
	Put(key string, input interface{}, expire ...int) error
	// 批量保存/过期时间(秒)
	PutBatch(objs ...*PutObj) error
	// 删除
	Del(input ...string) error
	// 查询全部key数量
	Size(pattern ...string) (int, error)
	// 查询全部key
	Keys(pattern ...string) ([]string, error)
	// 查询全部key
	Values(pattern ...string) ([]interface{}, error)
	// 查询key是否存在
	Exists(key string) (bool, error)
	// 查询队列数据
	Brpop(key string, expire int64, result interface{}) error
	BrpopString(key string, expire int64) (string, error)
	BrpopInt64(key string, expire int64) (int64, error)
	BrpopFloat64(key string, expire int64) (float64, error)
	BrpopBool(key string, expire int64) (bool, error)
	// 发送队列数据
	Rpush(key string, val interface{}) error
	// 发送订阅数据
	Publish(key string, val interface{}, try ...int) (bool, error)
	// 监听订阅数据
	Subscribe(key string, timeout int, call func(msg string) (bool, error)) error
	// 发送lua脚本
	LuaScript(script string, key []string, val ...interface{}) (interface{}, error)
	// 清空全部key-value
	Flush() error
}

缓存定义接口接口

func NewLocalCache

func NewLocalCache(a, b int) Cache

a默认缓存时间/分钟 b默认校验数据间隔时间/分钟

type CacheManager

type CacheManager struct{}

缓存管理器

func (*CacheManager) Brpop

func (self *CacheManager) Brpop(key string, expire int64, result interface{}) error

func (*CacheManager) BrpopBool

func (self *CacheManager) BrpopBool(key string, expire int64) (bool, error)

func (*CacheManager) BrpopFloat64

func (self *CacheManager) BrpopFloat64(key string, expire int64) (float64, error)

func (*CacheManager) BrpopInt64

func (self *CacheManager) BrpopInt64(key string, expire int64) (int64, error)

func (*CacheManager) BrpopString

func (self *CacheManager) BrpopString(key string, expire int64) (string, error)

func (*CacheManager) Del

func (self *CacheManager) Del(key ...string) error

func (*CacheManager) Exists added in v1.0.92

func (self *CacheManager) Exists(key string) (bool, error)

func (*CacheManager) Flush

func (self *CacheManager) Flush() error

func (*CacheManager) Get

func (self *CacheManager) Get(key string, input interface{}) (interface{}, bool, error)

func (*CacheManager) GetBool

func (self *CacheManager) GetBool(key string) (bool, error)

func (*CacheManager) GetFloat64

func (self *CacheManager) GetFloat64(key string) (float64, error)

func (*CacheManager) GetInt64

func (self *CacheManager) GetInt64(key string) (int64, error)

func (*CacheManager) GetString

func (self *CacheManager) GetString(key string) (string, error)

func (*CacheManager) Keys

func (self *CacheManager) Keys(pattern ...string) ([]string, error)

func (*CacheManager) LuaScript

func (self *CacheManager) LuaScript(script string, key []string, val ...interface{}) (interface{}, error)

func (*CacheManager) Publish

func (self *CacheManager) Publish(key string, val interface{}, try ...int) (bool, error)

func (*CacheManager) Put

func (self *CacheManager) Put(key string, input interface{}, expire ...int) error

func (*CacheManager) PutBatch

func (self *CacheManager) PutBatch(objs ...*PutObj) error

func (*CacheManager) Rpush

func (self *CacheManager) Rpush(key string, val interface{}) error

func (*CacheManager) Size

func (self *CacheManager) Size(pattern ...string) (int, error)

func (*CacheManager) Subscribe

func (self *CacheManager) Subscribe(key string, timeout int, call func(msg string) (bool, error)) error

exp second

func (*CacheManager) Values

func (self *CacheManager) Values(pattern ...string) ([]interface{}, error)

type LocalMapManager

type LocalMapManager struct {
	CacheManager
	// contains filtered or unexported fields
}

本地缓存管理器

func (*LocalMapManager) Del

func (self *LocalMapManager) Del(key ...string) error

func (*LocalMapManager) Exists added in v1.0.92

func (self *LocalMapManager) Exists(key string) (bool, error)

func (*LocalMapManager) Flush

func (self *LocalMapManager) Flush() error

func (*LocalMapManager) Get

func (self *LocalMapManager) Get(key string, input interface{}) (interface{}, bool, error)

func (*LocalMapManager) GetBool

func (self *LocalMapManager) GetBool(key string) (bool, error)

func (*LocalMapManager) GetFloat64

func (self *LocalMapManager) GetFloat64(key string) (float64, error)

func (*LocalMapManager) GetInt64

func (self *LocalMapManager) GetInt64(key string) (int64, error)

func (*LocalMapManager) GetString

func (self *LocalMapManager) GetString(key string) (string, error)

func (*LocalMapManager) NewCache

func (self *LocalMapManager) NewCache(a, b int) Cache

a默认缓存时间/分钟 b默认校验数据间隔时间/分钟

func (*LocalMapManager) Put

func (self *LocalMapManager) Put(key string, input interface{}, expire ...int) error

func (*LocalMapManager) Size

func (self *LocalMapManager) Size(pattern ...string) (int, error)

数据量大时请慎用

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

Lock represents a held lock.

type PutObj

type PutObj struct {
	Key    string
	Value  interface{}
	Expire int
}

type RedisConfig

type RedisConfig struct {
	DsName      string
	Host        string
	Port        int
	Password    string
	MaxIdle     int
	MaxActive   int
	IdleTimeout int
	Network     string
}

type RedisManager

type RedisManager struct {
	CacheManager
	DsName string
	Pool   *redis.Pool
}

func NewRedis

func NewRedis(ds ...string) (*RedisManager, error)

func (*RedisManager) Brpop

func (self *RedisManager) Brpop(key string, expire int64, result interface{}) error

func (*RedisManager) BrpopBool

func (self *RedisManager) BrpopBool(key string, expire int64) (bool, error)

func (*RedisManager) BrpopFloat64

func (self *RedisManager) BrpopFloat64(key string, expire int64) (float64, error)

func (*RedisManager) BrpopInt64

func (self *RedisManager) BrpopInt64(key string, expire int64) (int64, error)

func (*RedisManager) BrpopString

func (self *RedisManager) BrpopString(key string, expire int64) (string, error)

func (*RedisManager) Client

func (self *RedisManager) Client(ds ...string) (*RedisManager, error)

func (*RedisManager) Close

func (self *RedisManager) Close(conn redis.Conn)

func (*RedisManager) Del

func (self *RedisManager) Del(key ...string) error

func (*RedisManager) Exists added in v1.0.92

func (self *RedisManager) Exists(key string) (bool, error)

func (*RedisManager) Flush

func (self *RedisManager) Flush() error

func (*RedisManager) Get

func (self *RedisManager) Get(key string, input interface{}) (interface{}, bool, error)

func (*RedisManager) GetBool

func (self *RedisManager) GetBool(key string) (bool, error)

func (*RedisManager) GetFloat64

func (self *RedisManager) GetFloat64(key string) (float64, error)

func (*RedisManager) GetInt64

func (self *RedisManager) GetInt64(key string) (int64, error)

func (*RedisManager) GetString

func (self *RedisManager) GetString(key string) (string, error)

func (*RedisManager) InitConfig

func (self *RedisManager) InitConfig(input ...RedisConfig) (*RedisManager, error)

func (*RedisManager) Keys

func (self *RedisManager) Keys(pattern ...string) ([]string, error)

func (*RedisManager) LuaScript

func (self *RedisManager) LuaScript(cmd string, key []string, val ...interface{}) (interface{}, error)

func (*RedisManager) Publish

func (self *RedisManager) Publish(key string, val interface{}, try ...int) (bool, error)

func (*RedisManager) Put

func (self *RedisManager) Put(key string, input interface{}, expire ...int) error

func (*RedisManager) PutBatch

func (self *RedisManager) PutBatch(objs ...*PutObj) error

func (*RedisManager) Rpush

func (self *RedisManager) Rpush(key string, val interface{}) error

func (*RedisManager) Size

func (self *RedisManager) Size(pattern ...string) (int, error)

func (*RedisManager) SpinLockWithTimeout

func (self *RedisManager) SpinLockWithTimeout(resource string, trySecond, expSecond int, call func() error) error

func (*RedisManager) Subscribe

func (self *RedisManager) Subscribe(key string, expSecond int, call func(msg string) (bool, error)) error

func (*RedisManager) TryLockWithTimeout

func (self *RedisManager) TryLockWithTimeout(resource string, expSecond int, call func() error) error

func (*RedisManager) Values

func (self *RedisManager) Values(pattern ...string) ([]interface{}, error)

Directories

Path Synopsis
Package rate provides a rate limiter.
Package rate provides a rate limiter.

Jump to

Keyboard shortcuts

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