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

Memcache

Release Discord Test Security Linter

一个使用 bradfitz/gomemcache 的 Memcache 存储驱动程序。

注意:需要 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() *mc.Client

安装

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

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

然后安装 memory 实现

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

示例

导入 storage 包。

import "github.com/gofiber/storage/memcache"

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

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

// Initialize custom config
store := memcache.New(memcache.Config{
Servers: "localhost:11211",
})

配置

type Config struct {
// Server list divided by ,
// i.e. server1:11211, server2:11212
//
// Optional. Default is "127.0.0.1:11211"
Servers string

// Reset clears any existing keys in existing Table
//
// Optional. Default is false
Reset bool
}

默认配置

var ConfigDefault = Config{
Servers: "127.0.0.1:11211",
}