cache

package module
v0.0.0-...-a2c2b16 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

yo-cache based on Redis

基础数据类型抽象,分布式锁或者消息队列,单独封装。

安装

go get -u github.com/zhangjie2012/yo-cache@main

特性

  • 基础类型:object, string, int/int64, float64, bool
  • Set
  • List

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotExist       = errors.New("ERROR: key not exist")
	ErrInitRepeat     = errors.New("ERROR: init repeat")
	ErrAppNameInvalid = errors.New("ERROR: invalid appname")
)

Functions

func C

func C() *redis.Client

C expose redis client for native redis library visit

func Close

func Close() (err error)

func ComposeKey

func ComposeKey(rawkey string) string

ComposeKey 合成 key, 模块使用 `:` 分隔, 子模块使用 `.`

func ComposeKeys

func ComposeKeys(keys ...string) string

ComposeKeys

func Del

func Del(ctx context.Context, key string) error

func ErrorWrapper

func ErrorWrapper(err error) error

ErrorWrapper 错误码劫持, 全局扩展

func GetBool

func GetBool(ctx context.Context, key string) (bool, error)

func GetBytes

func GetBytes(ctx context.Context, key string) ([]byte, error)

func GetFloat64

func GetFloat64(ctx context.Context, key string) (float64, error)

func GetInt

func GetInt(ctx context.Context, key string) (int, error)

func GetInt64

func GetInt64(ctx context.Context, key string) (int64, error)

func GetObject

func GetObject(ctx context.Context, key string, value interface{}) error

func GetString

func GetString(ctx context.Context, key string) (string, error)

func Init

func Init(ctx context.Context, appName string, c *datastruct.RedisConf) error

Init 初始化 cache, appName 用于 key 隔离

func PTTL

func PTTL(ctx context.Context, key string) (time.Duration, error)

PTTL milliseconds resolution - The command returns -1 if the key exists but has no associated expire. - The command returns -2 if the key does not exist.

func SetBool

func SetBool(ctx context.Context, key string, b bool, expire time.Duration) error

func SetBytes

func SetBytes(ctx context.Context, key string, value []byte, expire time.Duration) error

Set/Get bytes

func SetFloat64

func SetFloat64(ctx context.Context, key string, value float64, expire time.Duration) error

func SetInt

func SetInt(ctx context.Context, key string, value int, expire time.Duration) error

func SetInt64

func SetInt64(ctx context.Context, key string, value int64, expire time.Duration) error

func SetObject

func SetObject(ctx context.Context, key string, value interface{}, expire time.Duration) error

Set/Get object

func SetString

func SetString(ctx context.Context, key string, value string, expire time.Duration) error

func TTL

func TTL(ctx context.Context, key string) (time.Duration, error)

TTL seconds resolution - The command returns -1 if the key exists but has no associated expire. - The command returns -2 if the key does not exist.

Types

This section is empty.

Jump to

Keyboard shortcuts

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