Documentation ¶
Overview ¶
Package db @Description: 数据缓存相关 @Link https://github.com/bsm/redislock redis分布式锁
Index ¶
- Constants
- func AddListItem[Val any](key string, timeout time.Duration, val ...Val) (err error)
- func ConvertCamelToSnake(s string) string
- func Del(key string)
- func DelNow(key string)
- func FormatKey(args ...string) string
- func Get[Res any](key string) (res Res, success bool)
- func GetConn() *sql.Conn
- func GetList[Res any](key string) []Res
- func GetListLimit[Res any](key string, start, end int64) []Res
- func GetMap[Key cacheKey, Val any](key string) (res map[Key]Val, success bool)
- func PutMap[Key cacheKey, Val any](key string, field Key, val Val, timeout time.Duration)
- func Run()
- func Set(key string, val any, timeout time.Duration)
- func WithCacheModule(module tgf.CacheModule)
- type AutoCacheBuilder
- func (a *AutoCacheBuilder[Key, Val]) New() IAutoCacheService[Key, Val]
- func (a *AutoCacheBuilder[Key, Val]) WithAutoCache(cacheKey string, cacheTimeOut time.Duration) *AutoCacheBuilder[Key, Val]
- func (a *AutoCacheBuilder[Key, Val]) WithAutoClearPlugins(plugin IAutoCacheClearPlugin) *AutoCacheBuilder[Key, Val]
- func (a *AutoCacheBuilder[Key, Val]) WithCloseAutoClearCache() *AutoCacheBuilder[Key, Val]
- func (a *AutoCacheBuilder[Key, Val]) WithLongevityCache(updateInterval time.Duration) *AutoCacheBuilder[Key, Val]
- func (a *AutoCacheBuilder[Key, Val]) WithMemCache(memTimeOutSecond uint32) *AutoCacheBuilder[Key, Val]
- type HashAutoCacheBuilder
- func (h *HashAutoCacheBuilder[Val]) New() IHashCacheService[Val]
- func (h *HashAutoCacheBuilder[Val]) WithAutoCache(cacheKey string, cacheTimeOut time.Duration) *HashAutoCacheBuilder[Val]
- func (h *HashAutoCacheBuilder[Val]) WithAutoClearPlugins(plugin IAutoCacheClearPlugin) *HashAutoCacheBuilder[Val]
- func (h *HashAutoCacheBuilder[Val]) WithCloseAutoClearCache() *HashAutoCacheBuilder[Val]
- func (h *HashAutoCacheBuilder[Val]) WithLongevityCache(updateInterval time.Duration) *HashAutoCacheBuilder[Val]
- func (h *HashAutoCacheBuilder[Val]) WithMemCache(memTimeOutSecond uint32) *HashAutoCacheBuilder[Val]
- type IAutoCacheClearPlugin
- type IAutoCacheService
- func NewAutoCacheManager[Key cacheKey, Val any](memTimeOutSecond int64) IAutoCacheService[Key, Val]
- func NewDefaultAutoCacheManager[Key cacheKey, Val any](cacheKey string) IAutoCacheService[Key, Val]
- func NewLongevityAutoCacheManager[Key cacheKey, Val IModel](cacheKey string) IAutoCacheService[Key, Val]
- type IHashCacheService
- type IHashModel
- type IModel
- type Model
Constants ¶
View Source
const StateName = "state"
Variables ¶
This section is empty.
Functions ¶
func AddListItem ¶
func ConvertCamelToSnake ¶
func FormatKey ¶ added in v1.0.7
FormatKey @Description: format redis key,拼接key. @example: FormatKey("user",1001) => user:1001 @param args @return string
func GetListLimit ¶
func WithCacheModule ¶
func WithCacheModule(module tgf.CacheModule)
Types ¶
type AutoCacheBuilder ¶
type AutoCacheBuilder[Key cacheKey, Val any] struct { // contains filtered or unexported fields }
AutoCacheBuilder [Key comparable,Val any] @Description: 自动化缓存Builder
func NewAutoCacheBuilder ¶
func NewAutoCacheBuilder[Key cacheKey, Val any]() *AutoCacheBuilder[Key, Val]
func (*AutoCacheBuilder[Key, Val]) New ¶
func (a *AutoCacheBuilder[Key, Val]) New() IAutoCacheService[Key, Val]
func (*AutoCacheBuilder[Key, Val]) WithAutoCache ¶
func (a *AutoCacheBuilder[Key, Val]) WithAutoCache(cacheKey string, cacheTimeOut time.Duration) *AutoCacheBuilder[Key, Val]
func (*AutoCacheBuilder[Key, Val]) WithAutoClearPlugins ¶
func (a *AutoCacheBuilder[Key, Val]) WithAutoClearPlugins(plugin IAutoCacheClearPlugin) *AutoCacheBuilder[Key, Val]
func (*AutoCacheBuilder[Key, Val]) WithCloseAutoClearCache ¶
func (a *AutoCacheBuilder[Key, Val]) WithCloseAutoClearCache() *AutoCacheBuilder[Key, Val]
func (*AutoCacheBuilder[Key, Val]) WithLongevityCache ¶
func (a *AutoCacheBuilder[Key, Val]) WithLongevityCache(updateInterval time.Duration) *AutoCacheBuilder[Key, Val]
func (*AutoCacheBuilder[Key, Val]) WithMemCache ¶
func (a *AutoCacheBuilder[Key, Val]) WithMemCache(memTimeOutSecond uint32) *AutoCacheBuilder[Key, Val]
type HashAutoCacheBuilder ¶
type HashAutoCacheBuilder[Val IHashModel] struct { AutoCacheBuilder[string, Val] // contains filtered or unexported fields }
func NewHashAutoCacheBuilder ¶
func NewHashAutoCacheBuilder[Val IHashModel]() *HashAutoCacheBuilder[Val]
func (*HashAutoCacheBuilder[Val]) New ¶
func (h *HashAutoCacheBuilder[Val]) New() IHashCacheService[Val]
func (*HashAutoCacheBuilder[Val]) WithAutoCache ¶
func (h *HashAutoCacheBuilder[Val]) WithAutoCache(cacheKey string, cacheTimeOut time.Duration) *HashAutoCacheBuilder[Val]
func (*HashAutoCacheBuilder[Val]) WithAutoClearPlugins ¶
func (h *HashAutoCacheBuilder[Val]) WithAutoClearPlugins(plugin IAutoCacheClearPlugin) *HashAutoCacheBuilder[Val]
func (*HashAutoCacheBuilder[Val]) WithCloseAutoClearCache ¶
func (h *HashAutoCacheBuilder[Val]) WithCloseAutoClearCache() *HashAutoCacheBuilder[Val]
func (*HashAutoCacheBuilder[Val]) WithLongevityCache ¶
func (h *HashAutoCacheBuilder[Val]) WithLongevityCache(updateInterval time.Duration) *HashAutoCacheBuilder[Val]
func (*HashAutoCacheBuilder[Val]) WithMemCache ¶
func (h *HashAutoCacheBuilder[Val]) WithMemCache(memTimeOutSecond uint32) *HashAutoCacheBuilder[Val]
type IAutoCacheClearPlugin ¶
type IAutoCacheService ¶
type IAutoCacheService[Key cacheKey, Val any] interface { Get(key ...Key) (val Val, err error) Set(val Val, key ...Key) (success bool) Push(key ...Key) Remove(key ...Key) (success bool) Reset() IAutoCacheService[Key, Val] Range(f func(Key, Val) bool) }
func NewAutoCacheManager ¶
func NewAutoCacheManager[Key cacheKey, Val any](memTimeOutSecond int64) IAutoCacheService[Key, Val]
NewAutoCacheManager [Key comparable, Val any] @Description: 创建一个持久化的自动化数据管理,包含本地缓存,不包含持久化数据落地(mysql),cache缓存(redis)
func NewDefaultAutoCacheManager ¶
func NewDefaultAutoCacheManager[Key cacheKey, Val any](cacheKey string) IAutoCacheService[Key, Val]
NewDefaultAutoCacheManager [Key comparable, Val any]
@Description: 创建一个默认的自动化数据管理,默认不包含持久化数据落地(mysql),包含本地缓存,cache缓存(redis) @param cacheKey cache缓存使用的组合key,例如user:1001 那么这里应该传入user即可,拼装方式为cacheKey:key @return IAutoCacheService [Key comparable, Val any] 返回一个全新的自动化数据缓存管理对象
func NewLongevityAutoCacheManager ¶
func NewLongevityAutoCacheManager[Key cacheKey, Val IModel](cacheKey string) IAutoCacheService[Key, Val]
NewLongevityAutoCacheManager [Key comparable, Val any]
@Description: 创建一个持久化的自动化数据管理,包含持久化数据落地(mysql),包含本地缓存,cache缓存(redis) @param cacheKey @param tableName @return IAutoCacheService [Key comparable, Val any]
type IHashCacheService ¶
type IHashCacheService[Val any] interface { IAutoCacheService[string, Val] GetAll(key ...string) (val []Val, err error) }
type IHashModel ¶
Click to show internal directories.
Click to hide internal directories.