Skip to content

abhicnv007/goku

Repository files navigation

Goku

Build Status Go Report codecov

Goku is a library written in Go to create a simple thread safe in-memory datastore that is persisted to disk.

Usage

package main

import (
    "fmt"
    "github.com/abhicnv007/goku"
)

func main() {
    g := goku.New(".db")
    defer g.Close()

    g.Add("foo", "bar")
    if val, ok := g.Get("foo"); ok {
        // use val
        fmt.Println(val) // Output: bar
    }
}

How does it work?

Goku creates an append only file at the location and logs out all operations to this file. In the event of a crash, the events from log are replayed and the data is reconstructed in memory.

g := goku.New(".db")
g.Add("foo", "bar")
// many more adds

// program crash

g = goku.New(".db") // load the data back from the file
g.Get("foo") // bar

The .db file can be freely trnasferred.

Benchmarks

goos: darwin
goarch: amd64
pkg: github.com/abhicnv007/goku
BenchmarkAdd-12    	  275427	     19766 ns/op	   10483 B/op	       2 allocs/op
BenchmarkGet-12    	44926000	       401 ns/op	       0 B/op	       0 allocs/op

TODO

  1. Allow for dump and restore
  2. Test file corruption

About

Go library to create in-memory datastore with disk persistence.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages