cache

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func InitMem added in v0.1.4

func InitMem()

func InitRedis added in v0.1.4

func InitRedis(host string, password string, db int)

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 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(host string, password string, db int) (ICache, error)

Jump to

Keyboard shortcuts

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