storage

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del

func Del(key string) error

func Get

func Get(key string) (any, error)

func Save

func Save(key string, value any, ttl time.Duration) error

Types

type Item

type Item struct {
	Value      any
	ExpireTime time.Time
}

Item 封装存储的值和过期时间

type MemoryStorage

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

MemoryStorage 实现 Storage 接口

func (*MemoryStorage) Close

func (ms *MemoryStorage) Close()

Close 停止后台协程(可选,用于优雅关闭)

func (*MemoryStorage) Del

func (ms *MemoryStorage) Del(key string) error

Del 删除键对应的值

func (*MemoryStorage) Get

func (ms *MemoryStorage) Get(key string) (any, error)

Get 获取键对应的值(若已过期则返回 nil)

func (*MemoryStorage) Save

func (ms *MemoryStorage) Save(key string, value any, ttl time.Duration) error

Save 保存键值对,并设置 TTL

type Storage

type Storage interface {
	Save(key string, value any, ttl time.Duration) error
	Get(key string) (any, error)
	Del(key string) error
}

func NewMemoryStorage

func NewMemoryStorage() Storage

NewMemoryStorage 创建一个新的内存存储实例,并启动后台清理协程

Jump to

Keyboard shortcuts

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