Skip to content

Instantly share code, notes, and snippets.

@zjshen14
Created April 17, 2019 22:12
Show Gist options
  • Save zjshen14/c572dcc68bd707dab9d182eeb742c508 to your computer and use it in GitHub Desktop.
Save zjshen14/c572dcc68bd707dab9d182eeb742c508 to your computer and use it in GitHub Desktop.
opts := badger.DefaultOptions
opts.Dir = "data1"
opts.ValueDir = "data2"
opts.TableLoadingMode = options.MemoryMap
db, _ := badger.Open(opts)
go func() {
for {
err := db.Update(func(txn *badger.Txn) error {
prefix := []byte("abc")
for i := 0; i < 10000; i++ {
key := sha256.Sum256([]byte(fmt.Sprintf("%d", rand.Int())))
val := sha256.Sum256([]byte(fmt.Sprintf("%d", rand.Int())))
err := txn.Set(append(prefix, key[:]...), val[:])
if err != nil {
return err
}
}
return nil
})
if err != nil {
log.Printf("Error when committing index: %s", err.Error())
} else {
log.Print("Committed index")
}
}
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment