cache

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 5 Imported by: 0

README

使用方法

import (
    "context"
    "gintpl/pkg/storage/cache"
)

// 先初始化
cache.InitRedisCache(redis.Client)

//使用
ctx := context.Background()
ttl := 5 // 秒
cache.Set(ctx, "key1", 1, ttl)
cache.Get(ctx, "key1")
var v int
cache.GetScan(ctx, "key1", &v)
cache.Del(ctx, "key1")
cache.GetOrSet(ctx, "key1", ttl, function() any {
    return "val"
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del

func Del(ctx context.Context, key string)

func Get

func Get(ctx context.Context, key string) string

func GetOrSet

func GetOrSet(ctx context.Context, key string, sec int, fn func() any) string

func GetScan

func GetScan(ctx context.Context, key string, dst any) error

func InitRedisCache

func InitRedisCache(client *redis.Client)

InitRedisCache 创建redis缓存

func Set

func Set(ctx context.Context, key string, val any, sec int) error

Types

type Cacher

type Cacher interface {
	Set(ctx context.Context, key string, val any, sec int) error
	Del(ctx context.Context, key string)
	Get(ctx context.Context, key string) string
	GetScan(ctx context.Context, key string, dst any) error
	GetOrSet(ctx context.Context, key string, sec int, fn func() any) string
}

Jump to

Keyboard shortcuts

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