kvas
is a minimal overhead key value store backed by the filesystem.
It comes with the following features:
- writes only happen for new data (verified with a SHA-256 hash);
- modifications are timestamped, allowing querying last modified by a timestamp;
- an in-memory index, allowing fast operations like confirming whether value set contains a key, enumerations;
- specific values in a set are stored individually as files;
- reductions - a slice of property values per key for fast in-memory operations like finding all keys that match specific value.
- list of reduction - a slice of reductions with additional fabric that establishes data relationships for transparent common operations (aliasing, joins).
- Run go get
github.com/boggydigital/kvas
- Import
github.com/boggydigital/kvas
- For a key value set - connect to a local store with
kvas.ConnectLocal(directory, extension)
- Extensions supported:
kvas.JsonExt (.json)
,kvas.GobExt (.gob)
- Extensions supported:
- Use this key value set client to
Get
,Set
,Cut
values, as well as filter usingCreatedAfter
,ModifiedAfter
, etc.
kvas
comes with the following types:
KeyValues
- key value store backed by local filesystemReduxValues
- key reductions store (backed bykvas.KeyValues
)ReduxAssets
- collection ofReduxValues
plus additional data relationship fabric
NOTE: Error handling omitted for brevity.
lkv, _ := kvas.ConnectLocal(os.TempDir(), kvas.JsonExt)
key := "value1"
start := time.Now().Unix()
_ = lkv.Set(key, strings.NewReader(key))
if lkv.Has(key) {
readCloser, _ := lkv.Get(key)
defer readCloser.Close()
// use readCloser to read data stored under "value1" key
}
fmt.Println(lkv.ModifiedAfter(start, false)) // prints: [value1]
NOTE: Error handling omitted for brevity.
rdx, _ := kvas.ConnectRedux(os.TempDir(), "titles")
for _, key := range rdx.Keys() {
allKeyTitles, _ := rdx.GetAllValues(key)
// process all titles for a key
}
// find all keys that have values containing "specific_title" (any case)
matches := rdx.Match([]string{"specific_title"}, nil, true, true)
NOTE: Error handling omitted for brevity.
rxa, _ := kvas.ConnectReduxAssets(os.TempDir(), nil, "titles", "country")
query := map[string][]string{
"title": {"title1", "title2"},
"country": {"states"},
}
// find all keys across "titles" and "countries" reductions that match query
matches := rxa.Match(query, true)