go get -u github.com/nickalie/fskv
Storage is safe to be used in multi-thread and multi-process environments.
package main
import (
"github.com/nickalie/fskv"
"log"
"fmt"
)
func main() {
db, err := fskv.NewFSKV("data")
if err != nil {
log.Fatal(err)
}
db.Set("mykey", []byte("somevalue"))
value, _ := db.Get("mykey")
fmt.Println("Got: " + string(value))
}
Buckets are collections of key/value pairs within the storage. You can create any amount of nested buckets
bucket, _ := db.GetBucket("mybucket")
bucket.Set("some_key", []byte("some_value"))
value, _ := bucket.Get("another_key")
childBucket, := bucket.GetBucket("childbucket")
To iterate over the keys:
db.Scan("", func(key string, value []byte) bool {
fmt.Printf("key: %s, value: %s\n", key, string(value))
return false
})
You can specify prefix to iterate over keys with that prefix.