Memcache


bradfitz/gomemcache를 사용하는 Memcache 스토리지 드라이버입니다.

참고: Go 1.19 이상이 필요합니다

Table of Contents

  • Signatures

  • Installation

  • Examples

  • Config

  • Default Config

Signatures

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

Installation

Memory는 모듈 지원을 포함한 최신 2개 Go 버전에서 테스트되었습니다. 아직 모듈을 초기화하지 않았다면 먼저 초기화하세요:

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

그런 다음 memory 구현을 설치하세요:

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

Examples

스토리지 패키지를 import 하세요.

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

다음과 같은 방법으로 스토리지를 생성할 수 있습니다:

// 기본 config로 초기화
store := memcache.New()

// 사용자 정의 config로 초기화
store := memcache.New(memcache.Config{
  Servers: "localhost:11211",
})

Config

type Config struct {
  // 콤마로 구분된 서버 목록
  // 예: server1:11211, server2:11212
  //
  // 선택 사항. 기본값은 "127.0.0.1:11211"
  Servers string

  // Reset은 기존 테이블에 있는 키를 모두 지웁니다
  //
  // 선택 사항. 기본값은 false
  Reset bool
}

Default Config

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

Last updated