Pebble
cockroachdb/pebble를 사용한 빠른 key-value DB
참고: 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() *badger.DB
Installation
Pebble은 모듈을 지원하는 최신 Go 버전 2개에서 테스트되었습니다. 아직 모듈을 초기화하지 않았다면 먼저 다음을 수행해야 합니다:
go mod init github.com/<user>/<repo>
참고: 이 단계는 기존 모듈이 없는 경우에만 필요합니다.
그런 다음 Pebble 구현을 설치합니다:
go get github.com/gofiber/storage/pebble/v2
Examples
스토리지 패키지를 import합니다.
import "github.com/gofiber/storage/pebble/v2"
다음과 같은 방법으로 스토리지를 생성할 수 있습니다:
// 기본 설정으로 초기화
store := pebble.New()
// 사용자 정의 설정으로 초기화
store := pebble.New(pebble.Config{
Path: "db",
WriteOptions: &pebble.WriteOptions{},
})
Config
type Config struct {
// 데이터베이스 이름
//
// 선택사항. 기본값은 "./db"
Path string
// 쓰기 작업 중 쓰기 옵션 전달
//
// 선택사항. 기본값은 nil
WriteOptions *pebble.WriteOptions
}
Default Config
var ConfigDefault = Config{
Path: "db",
WriteOptions: &pebble.WriteOptions{},
}
Last updated