Read this in other languages: 简体中文
lmdb-storage is a Go language library used to save key-value data. It is a further packaging of the lmdb database. This library further adds the functions of batch reading and writing and automatic partitioning based on lmdb-go, which is more suitable for dealing with large amounts of data reading and writing.
Use the go get to install lmdb-storage.
go get github.com/dingyuqi/lmdb-storageCall NewLmdbDriver() to get a Driver object, providing a total of three parameters:
root: the root path to save datamapSize: size of one DB fileblockSize: batch size of reading and writing
Tip
If you do not want to set mapSize and blockSize, you can call NewDefaultLmdbDriver().
This function only needs to provide the root path parameter. The default mapSize is 5MB and blockSize is 10000.
package main
import (
lmdb "github.com/dingyuqi/lmdb-storage"
"log"
)
// TestDataPath lmdb database root path
// please use your own local path
var TestDataPath = "D:/test_lmdb"
func main() {
// init a default driver
defaultDriver, err := lmdb.NewDefaultLmdbDriver(TestDataPath)
if err != nil {
log.Fatalln(err)
}
// init a user-defined driver
definedDriver, err := lmdb.NewLmdbDriver(TestDataPath, 5*1024*1024, 10000)
if err != nil {
log.Fatalln(err)
}
}Important
If a certain key in the query cannot be searched in the database, it will not appear in the returned result.
package main
import (
lmdb "github.com/dingyuqi/lmdb-storage"
"log"
)
// TestDataPath lmdb database root path
// please use your own local path
var TestDataPath = "D:/test_lmdb"
func main() {
// init a default driver
driver, err := lmdb.NewDefaultLmdbDriver(TestDataPath)
if err != nil {
log.Fatalln(err)
}
data := map[string]struct{}{"3": {}, "2": {}, "1": {}, "102": {}}
result, err := driver.Get(data)
if err != nil {
log.Println("get error", err)
return
}
log.Println("result:", result)
}MIT License