dbs

package module
v0.0.0-...-cd9dfe2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: AGPL-3.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

dbs

Documentation

Index

Constants

View Source
const (
	// DataStructureBTree 支持范围查找,也就是前缀查找
	NutsdbDataStruct = nutsdb.DataStructureBTree
)

Variables

This section is empty.

Functions

func BuntdbKeyExists

func BuntdbKeyExists(db *buntdb.DB, key string) (bool, error)

func BuntdbKeysAllExists

func BuntdbKeysAllExists(db *buntdb.DB, keys []string) (bool, error)

func NewBuntdb

func NewBuntdb(dbName string, faster bool) (*buntdb.DB, error)

NewBuntdb 创建buntdb数据库,容量受内存大小限制 dbName: 数据库文件名,如果为空,则使用内存模式 faster: true 快速模式,长时间间隔写盘+手动写盘和压缩 faster: false 慢速模式,间隔一秒写盘+自动压缩 外部需要执行 db.Close()、db.Shrink()或db.Save()

func NewSqliteDb

func NewSqliteDb(ctx context.Context, dbPath string, customLogger logger.Interface) (*gorm.DB, error)

NewSqliteDb 初始化数据库

func SyncMemToFile

func SyncMemToFile(memDb *buntdb.DB, fileDb *NutsdbInfo) error

方案2:全量同步 操作缓慢且影响内存数据库的性能,需要在业务低峰期执行(比如:中午休息时间) 读性能无损:快照读取不影响主库写入速度 写性能损耗:仅来自版本树维护(约 3-5%) 假设数据库含 100 万条记录: 全量遍历耗时 ≈ 50ms~200ms 在此期间可能发生: 1. 已遍历的键被修改(数据版本不一致) 2. 新键插入(数据遗漏) 3. 未遍历的键被删除(数据丢失)

Types

type NutsdbInfo

type NutsdbInfo struct {
	Db *nutsdb.DB
	// contains filtered or unexported fields
}

func NewNutsdb

func NewNutsdb(dbName string, bucketNumber int, faster bool) (*NutsdbInfo, error)

NewNutsdb 创建nutsdb数据库,容量受磁盘大小限制 bucketNumber 分片数,一旦定下来,不能修改,否则出现数据获取不到 外部需要执行 db.Close() 若对一个key频繁操作,择机执行db.Merge()

func (*NutsdbInfo) GetShardBucket

func (n *NutsdbInfo) GetShardBucket(key []byte) string

推荐分片数 = (预估最大活跃连接数 × 2) / CPU核心数 其他hash库:"github.com/cespare/xxhash/v2"

func (*NutsdbInfo) GetShardBucket2

func (n *NutsdbInfo) GetShardBucket2(key []byte) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址