cache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedis

func NewRedis(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, error)

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"`   // 0.2s
	WriteTimeout types.Duration `mapstructure:"writeTimeout" yaml:"writeTimeout"` // 0.2s
}

Jump to

Keyboard shortcuts

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