cache

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheTypeMem   = "mem"
	CacheTypeRedis = "redis"
)

Variables

This section is empty.

Functions

func InitMem

func InitMem()

func InitRedis

func InitRedis(c *ConfigRedis) error

Types

type CacheMem

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

func (*CacheMem) Close

func (s *CacheMem) Close() error

func (*CacheMem) Get

func (s *CacheMem) Get(key string) (string, error)

读取缓存

func (*CacheMem) GetBytes

func (s *CacheMem) GetBytes(key string) ([]byte, error)

func (*CacheMem) Ping

func (s *CacheMem) Ping() (string, error)

func (*CacheMem) Set

func (s *CacheMem) Set(key string, val interface{}, expiration time.Duration) error

设置缓存

type CacheRedis

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

func (*CacheRedis) Close

func (c *CacheRedis) Close() error

func (*CacheRedis) Get

func (c *CacheRedis) Get(key string) (string, error)

读取缓存

func (*CacheRedis) GetBytes

func (c *CacheRedis) GetBytes(key string) ([]byte, error)

func (*CacheRedis) Ping

func (c *CacheRedis) Ping() (string, error)

func (*CacheRedis) Set

func (c *CacheRedis) Set(key string, val interface{}, expiration time.Duration) error

设置缓存

type ConfigRedis

type ConfigRedis struct {
	Host     string // redis 主机地址
	Password string // redis密码
	Db       int    // redis db
}

type ICache

type ICache interface {
	Set(key string, val interface{}, expiration time.Duration) error
	Get(key string) (string, error)
	GetBytes(key string) ([]byte, error) // 获取缓存的 bytes
	// GetKey() string                      // 生成key值
	Ping() (string, error)
	Close() error // 关闭连接
}

抽象 cache 类

func GetCache

func GetCache() ICache

全局唯一

func NewMemCache

func NewMemCache() ICache

func NewRedisCache

func NewRedisCache(c *ConfigRedis) (ICache, error)

Jump to

Keyboard shortcuts

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