V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
china521
V2EX  ›  分享创造

分享一个 Golang 的 KV 库, 支持多进程多线程,支持在 samba 的文件夹上创建数据库

  •  
  •   china521 · 2016-03-04 13:00:43 +08:00 · 3234 次点击
    这是一个创建于 2981 天前的主题,其中的信息可能已经有所发展或是发生改变。

    程序不需要大量的 KV 键保存, 但需要保存到共享目录上,还得支持多进程, 好多优秀的数据库不能在这样的环境下运行...

    没几行代码.就自己撸了个, 分享给大家, 相信有些 V 友会遇见这样的需求情况

    https://github.com/zeropool/go-dkv

    用的着的 Star 一下,哈哈.

    go-dkv

    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 条回复    2016-03-05 13:35:30 +08:00
    julor
        1
    julor  
       2016-03-05 13:35:30 +08:00 via Android
    消灭 0 回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2283 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 07:30 · PVG 15:30 · LAX 00:30 · JFK 03:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.