gpt4 book ai didi

go - Boltdb 中的批处理操作

转载 作者:IT老高 更新时间:2023-10-28 21:18:51 30 4
gpt4 key购买 nike

目前正在使用 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com