目前正在使用 db.Update() 更新 boltdb 中的键值。
err := db.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucket([]byte("widgets"))
if err != nil {
return err
}
if err := b.Put([]byte("foo"), []byte("bar")); err != nil {
return err
}
return nil
})
如何使用 go 例程使用 db.Batch() 操作?
最佳答案
只需从您的协程中调用 db.Batch() 即可。创建 Batch() 就是为了以这种方式使用。 documentation 中有一个示例.
关于go - Boltdb 中的批处理操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30908830/