redis

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package redis 提供 Redis 缓存服务

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache redis 缓存

func New

func New(name string, ttl time.Duration) *Cache

New 创建 redis 缓存实例

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, key string) error

Delete 从 redis 中删除指定的键

func (*Cache) Exists

func (c *Cache) Exists(ctx context.Context, key string) bool

Exists 检查 key 在 redis 中是否存在

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string, value any) error

Get 从 redis 中获取值,并存储到 value 中,若失败则返回 error

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, key string, value any, ttl time.Duration) error

Set 将 value 存储到 redis 中,若 ttl 为 0 则使用默认值(Cache.ttl)

Jump to

Keyboard shortcuts

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