Couchbase
couchbase/gocb를 사용하는 Couchbase storage 드라이버입니다.
참고: 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() gocb.Cluster
Installation
Couchbase는 모듈 지원과 함께 최신 Go 버전 2개에서 테스트되었습니다. 아직 초기화하지 않았다면 먼저 초기화해야 합니다:
go mod init github.com/<user>/<repo>
그런 다음 Couchbase 구현을 설치합니다:
go get github.com/gofiber/storage/couchbase/v2
Examples
storage 패키지를 import합니다.
import "github.com/gofiber/storage/couchbase/v2"
다음과 같은 방법으로 storage를 생성할 수 있습니다:
// 기본 config로 초기화
store := couchbase.New()
// 사용자 정의 config로 Couchbase storage 초기화
store := couchbase.New(couchbase.Config{
Host: "127.0.0.1:8091",
Username: "",
Password: "",
Bucket: 0,
ConnectionTimeout: 3* time.Second,
KVTimeout: 1* time.Second,
})
Config
type Config struct {
// Couchbase 클러스터에 연결할 애플리케이션 사용자 이름
Username string
// Couchbase 클러스터에 연결할 애플리케이션 비밀번호
Password string
// Couchbase 클러스터의 연결 문자열
Host string
// 연결할 버킷 이름
Bucket string
// Couchbase 클러스터 연결 타임아웃
ConnectionTimeout time.Duration
// Couchbase 클러스터에서 작업 수행 시 타임아웃
KVTimeout time.Duration
}
Default Config
// ConfigDefault는 기본 config입니다
var ConfigDefault = Config{
Host: "127.0.0.1:8091",
Username: "admin",
Password: "123456",
Bucket: "fiber_storage",
ConnectionTimeout: 3 * time.Second,
KVTimeout: 1 * time.Second,
}
Last updated