V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
china521

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

  •  
  •   china521 · Mar 4, 2016 · 3690 views
    This topic created in 3707 days ago, the information mentioned may be changed or developed.

    程序不需要大量的 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 replies    2016-03-05 13:35:30 +08:00
    julor
        1
    julor  
       Mar 5, 2016 via Android
    消灭 0 回复
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3585 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 10:59 · PVG 18:59 · LAX 03:59 · JFK 06:59
    ♥ Do have faith in what you're doing.