db

package
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Overview

Package db @Description: 数据缓存相关 @Link https://github.com/bsm/redislock redis分布式锁

Index

Constants

View Source
const StateName = "state"

Variables

This section is empty.

Functions

func AddListItem

func AddListItem[Val any](key string, timeout time.Duration, val ...Val) (err error)

func AddSetItem added in v1.0.15

func AddSetItem[Val any](key string, timeout time.Duration, val Val) (err error)

func ConvertCamelToSnake

func ConvertCamelToSnake(s string) string

func Del

func Del(key string)

func DelNow

func DelNow(key string)

func FormatKey added in v1.0.7

func FormatKey(args ...string) string

FormatKey @Description: format redis key,拼接key. @example: FormatKey("user",1001) => user:1001 @param args @return string

func Get

func Get[Res any](key string) (res Res, success bool)

Get [Res any] @Description: 通过二级缓存获取数据 @param key @return res

func GetAllSet added in v1.0.15

func GetAllSet[Res any](key string) []Res

func GetConn

func GetConn() *sql.Conn

func GetList

func GetList[Res any](key string) []Res

func GetListLimit

func GetListLimit[Res any](key string, start, end int64) []Res

func GetMap

func GetMap[Key cacheKey, Val any](key string) (res map[Key]Val, success bool)

func Incr added in v1.0.15

func Incr(key string, timeout time.Duration) (res int64, err error)

Incr @Description: 释放锁 @param l

func IncrBy added in v1.0.15

func IncrBy(key string, val float64, timeout time.Duration) (res float64, err error)

IncrBy @Description: 释放锁 @param l

func LLen added in v1.0.15

func LLen(key string) (res int64, err error)

LLen @Description: 获取list长度 @param l

func NewLock added in v1.0.11

func NewLock(key string) (*redislock.Lock, error)

NewLock @Description: 创建一个redis锁,用于分布式锁,需要在redis环境下使用,使用完毕后需要调用UnLock释放锁 @param key @return *redislock.Lock @return error

func PutMap

func PutMap[Key cacheKey, Val any](key string, field Key, val Val, timeout time.Duration)

func Run

func Run()

func Set

func Set(key string, val any, timeout time.Duration)

func UnLock added in v1.0.11

func UnLock(l *redislock.Lock)

UnLock @Description: 释放锁 @param l

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 IAutoCacheClearPlugin interface {
	PreClear(key string)
	PostClear(key string)
}

type IAutoCacheService

type IAutoCacheService[Key cacheKey, Val any] interface {
	Get(key ...Key) (val Val, err error)
	TryGet(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

type IHashModel interface {
	//主键key
	HashCachePkKey(key ...string) string

	//单项Key,调用Get,Set等操作函数的时候,需要保证这里的值有跟主键一起传进来
	HashCacheFieldByVal() string
	HashCacheFieldByKeys(key ...string) string
}

type IModel

type IModel interface {
	GetTableName() string
	Remove()
}

type Model

type Model struct {
	State uint8 //数据状态,0为删除,1为正常
}

func NewModel

func NewModel() Model

func (*Model) IsValid added in v1.0.7

func (m *Model) IsValid() bool

IsValid @Description: 是否有效 @receiver m @return bool

func (*Model) Remove

func (m *Model) Remove()

Jump to

Keyboard shortcuts

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