跳到主要内容
版本: valkey_v0.x.x

Memory

Release Discord Test Security Linter

一个内存存储驱动。

注意: 需要 Go 1.19 及以上版本

目录

签名

func New(config ...Config) Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() map[string]entry
func (s *Storage) Keys() ([][]byte, error)

安装

Memory 在最后两个支持模块的 Go 版本上进行了测试。因此,如果你还没有初始化模块,请确保先进行初始化

go mod init github.com/<user>/<repo>

然后安装 memory 实现

go get github.com/gofiber/storage/memory/v2

示例

导入存储包。

import "github.com/gofiber/storage/memory/v2"

你可以使用以下方法创建存储

// Initialize default config
store := memory.New()

// Initialize custom config
store := memory.New(memory.Config{
GCInterval: 10 * time.Second,
})

配置

type Config struct {
// Time before deleting expired keys
//
// Default is 10 * time.Second
GCInterval time.Duration
}

默认配置

var ConfigDefault = Config{
GCInterval: 10 * time.Second,
}