Memory


메모리에 저장하는 스토리지 드라이버입니다.

참고: 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() map[string]entry

func (s *Storage) Keys() ([][]byte, error)

Installation

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

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

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

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

Examples

storage 패키지를 임포트합니다.

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

다음과 같은 방법으로 storage를 생성할 수 있습니다:

// 기본 설정으로 초기화
store := memory.New()

// 사용자 정의 설정으로 초기화
store := memory.New(memory.Config{
    GCInterval: 10 * time.Second,
})

Config

type Config struct {
    // 만료된 키를 삭제하기 전 시간
    //
    // 기본값은 10 * time.Second
    GCInterval time.Duration
}

Default Config

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

Last updated