程序不需要大量的 KV 键保存, 但需要保存到共享目录上,还得支持多进程, 好多优秀的数据库不能在这样的环境下运行...
没几行代码.就自己撸了个, 分享给大家, 相信有些 V 友会遇见这样的需求情况
https://github.com/zeropool/go-dkv
用的着的 Star 一下,哈哈.
Golang simple KV Database use system's file system
Features:
- Support create a database in a samba directory
- Support Multi-process, Multi-thread
package main
import (
"fmt"
"github.com/zeropool/go-dkv"
)
type T struct {
A int
B string
}
func main() {
// create a database under folder test
db, err := dkv.NewKVDB("test", false)
if err != nil {
panic(db)
}
// can store any variable that can marshal with json
db.Set("Hello", "World")
db.Set("PI", 3.1415926)
db.Set("test", &T{1, "OK"})
fmt.Println("Hello:", db.Get("Hello"))
fmt.Println("dummy will nil:", db.Get("dummy"))
db.Interate(func(k string, v interface{}) {
fmt.Println(k, v)
})
db.Del("Hello")
// empty the database, will remove database directory
db.Cls()
db.Close()
}
1
julor 2016-03-05 13:35:30 +08:00 via Android
消灭 0 回复
|