Couchbase
一个使用 couchbase/gocb 的 Couchbase 存储驱动。
注意:需要 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() *gocb.Cluster
安装
Couchbase 在支持模块的最新两个 Go 版本上进行了测试。因此,如果您还没有这样做,请确保先初始化一个。
go mod init github.com/<user>/<repo>
然后安装 Couchbase 实现
go get github.com/gofiber/storage/couchbase/v2
示例
导入存储包。
import "github.com/gofiber/storage/couchbase/v2"
您可以使用以下方法创建存储
// Initialize default config
store := couchbase.New()
// Initialize Couchbase storage with custom config
store := couchbase.New(couchbase.Config{
Host: "127.0.0.1:8091",
Username: "",
Password: "",
Bucket: 0,
ConnectionTimeout: 3* time.Second,
KVTimeout: 1* time.Second,
})
配置
type Config struct {
// The application username to Connect to the Couchbase cluster
Username string
// The application password to Connect to the Couchbase cluster
Password string
// The connection string for the Couchbase cluster
Host string
// The name of the bucket to Connect to
Bucket string
// The timeout for connecting to the Couchbase cluster
ConnectionTimeout time.Duration
// The timeout for performing operations on the Couchbase cluster
KVTimeout time.Duration
}
默认配置
// ConfigDefault is the default 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,
}