Documentation ¶
Index ¶
- Constants
- Variables
- type Badger
- func (s *Badger) BatchDelete(keys [][]byte) error
- func (s *Badger) BatchGet(keys [][]byte) ([][]byte, error)
- func (s *Badger) BatchSet(keys, values [][]byte) error
- func (s *Badger) CheckAndGC()
- func (s *Badger) Close() error
- func (s *Badger) Delete(k []byte) error
- func (s *Badger) Get(k []byte) ([]byte, error)
- func (s *Badger) GetDbPath() string
- func (s *Badger) Has(k []byte) bool
- func (s *Badger) IterDB(fn func(k, v []byte) error) int64
- func (s *Badger) IterKey(fn func(k []byte) error) int64
- func (s *Badger) Open() error
- func (s *Badger) Set(k, v []byte) error
- func (s *Badger) WithDataPath(path string) *Badger
- type Bolt
- func (s *Bolt) BatchDelete(keys [][]byte) error
- func (s *Bolt) BatchGet(keys [][]byte) ([][]byte, error)
- func (s *Bolt) BatchSet(keys, values [][]byte) error
- func (s *Bolt) Close() error
- func (s *Bolt) Delete(k []byte) error
- func (s *Bolt) Get(k []byte) ([]byte, error)
- func (s *Bolt) GetDbPath() string
- func (s *Bolt) Has(k []byte) bool
- func (s *Bolt) IterDB(fn func(k, v []byte) error) int64
- func (s *Bolt) IterKey(fn func(k []byte) error) int64
- func (s *Bolt) Open() error
- func (s *Bolt) Set(k, v []byte) error
- func (s *Bolt) WALName() string
- func (s *Bolt) WithBucket(bucket string) *Bolt
- func (s *Bolt) WithDataPath(path string) *Bolt
- type IKeyValueDB
Constants ¶
View Source
const ( BOLT = iota BADGER )
Variables ¶
View Source
var ErrNoData = errors.New("没有数据")
Functions ¶
This section is empty.
Types ¶
type Badger ¶
type Badger struct {
// contains filtered or unexported fields
}
func (*Badger) WithDataPath ¶
type Bolt ¶
type Bolt struct {
// contains filtered or unexported fields
}
Bolt 存储结构
func (*Bolt) WithBucket ¶
func (*Bolt) WithDataPath ¶
使用 Builder 模式来构建 Bolt 结构体
type IKeyValueDB ¶
type IKeyValueDB interface { Open() error //初始化DB GetDbPath() string //获取存储数据的目录 Set(k, v []byte) error //写入<key, value> BatchSet(keys, values [][]byte) error //批量写入<key, value> Get(k []byte) ([]byte, error) //读取key对应的value BatchGet(keys [][]byte) ([][]byte, error) //批量读取,注意不保证顺序 Delete(k []byte) error //删除 BatchDelete(keys [][]byte) error //批量删除 Has(k []byte) bool //判断某个key是否存在 IterDB(fn func(k, v []byte) error) int64 //遍历数据库,返回数据的条数 IterKey(fn func(k []byte) error) int64 //遍历数据库,返回key的条数 Close() error //把内存中的数据flush到磁盘,同时释放文件锁 }
操作各类数据库的接口
func GetKetValueDB ¶
func GetKetValueDB(dbType int, path string) (IKeyValueDB, error)
工厂模式,可以根据传入的dbType构建不同的数据库产品,返回产品的接口
Click to show internal directories.
Click to hide internal directories.