Created
April 17, 2019 22:12
-
-
Save zjshen14/c572dcc68bd707dab9d182eeb742c508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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