cache

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedis

func NewRedis(appName string, cfg RedisConf) (redis.UniversalClient, error)

NewRedis Initialize redis connection.

Types

type Cache

type Cache interface {
	// SetMaxMemory size : 1KB 100KB 1M 2MB 1GB
	SetMaxMemory(size string) bool

	Set(key string, val any, expire time.Duration) error

	Get(key string, result any) error

	Del(key string) bool

	Exists(key string) bool

	Clear() bool
	// Keys 获取所有缓存中 key 的数量
	Keys() int64
}

func DefaultCache

func DefaultCache() Cache

func NewFreeCache

func NewFreeCache(maxMemorySize types.ByteSize) (Cache, error)

type LocalCacheConf

type LocalCacheConf struct {
	MaxSize types.ByteSize `mapstructure:"maxSize" yaml:"maxSize"` // 最大容量
}

type RedisConf

type RedisConf struct {
	Addrs        []string       `mapstructure:"addrs"` // [127.0.0.1:6379, 127.0.0.1:7000]
	Username     string         `mapstructure:"username"`
	Password     string         `mapstructure:"password" mask:""`
	DB           uint8          `mapstructure:"db"` // 集群模式下无效
	PoolSize     int            `mapstructure:"poolSize" yaml:"poolSize"`
	ReadTimeout  types.Duration `mapstructure:"readTimeout" yaml:"readTimeout" validate:"duration"`   // 0.2s
	WriteTimeout types.Duration `mapstructure:"writeTimeout" yaml:"writeTimeout" validate:"duration"` // 0.2s
}

type RedisManager added in v0.1.3

type RedisManager map[string]redis.UniversalClient

多数据源管理

func NewRedisManager added in v0.1.4

func NewRedisManager(appName string, cfgMap map[string]RedisConf) (RedisManager, error)

func (RedisManager) Default added in v0.1.3

func (m RedisManager) Default() redis.UniversalClient

func (RedisManager) Get added in v0.1.3

Jump to

Keyboard shortcuts

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