Pebble
一个使用 cockroachdb/pebble 的快速键值数据库
注意:需要 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() *badger.DB
安装
Pebble 在最新的两个支持模块的 Go 版本上进行了测试。所以如果你还没有初始化模块,请务必先初始化一个。
go mod init github.com/<user>/<repo>
注意:仅当你没有现有模块时才需要此步骤。
然后安装 Pebble 实现
go get github.com/gofiber/storage/pebble/v2
示例
导入存储包。
import "github.com/gofiber/storage/pebble/v2"
你可以使用以下方法创建存储
// Initialize default config
store := pebble.New()
// Initialize custom config
store := pebble.New(pebble.Config{
Path: "db",
WriteOptions: &pebble.WriteOptions{},
})
配置
type Config struct {
// Database name
//
// Optional. Default is "./db"
Path string
// Pass write options during write operations
//
// Optional. Default is nil
WriteOptions &pebble.WriteOptions{}
}
默认配置
var ConfigDefault = Config{
Path: "db",
WriteOptions: &pebble.WriteOptions{},
}