Valkeyrie
Distributed Key/Value Store Abstraction Library
Valkeyrie
valkeyrie
provides a Go native library to store metadata using Distributed Key/Value stores (or common databases).
Its goal is to abstract common store operations (Get
, Put
, List
, etc.) for multiple Key/Value store backends.
For example, you can easily implement a generic Leader Election algorithm on top of it (see the docker/leadership repository).
The benefit of valkeyrie
is not to duplicate the code for programs that should support multiple distributed Key/Value stores such as Consul
/etcd
/zookeeper
, etc.
Examples of Usage
You can refer to Examples for a basic overview of the library.
package main
import (
"context"
"log"
"time"
"github.com/kvtools/consul"
"github.com/kvtools/valkeyrie"
)
func main() {
ctx := context.Background()
config := &consul.Config{
ConnectionTimeout: 10 * time.Second,
}
kv, err := valkeyrie.NewStore(ctx, consul.StoreName, []string{"localhost:8500"}, config)
if err != nil {
log.Fatal("Cannot create store consul")
}
key := "foo"
err = kv.Put(ctx, key, []byte("bar"), nil)
if err != nil {
log.Fatalf("Error trying to put value at key: %v", key)
}
pair, err := kv.Get(ctx, key, nil)
if err != nil {
log.Fatalf("Error trying accessing value at key: %v", key)
}
log.Printf("value: %s", string(pair.Value))
err = kv.Delete(ctx, key)
if err != nil {
log.Fatalf("Error trying to delete key %v", key)
}
}
Compatibility
A storage backend in valkeyrie
implements (fully or partially) the Store interface.
Calls | Consul | Etcd | Zookeeper | Redis | BoltDB | DynamoDB |
---|---|---|---|---|---|---|
Put | ๐ข๏ธ | |||||
Get | ๐ข๏ธ | |||||
Delete | ๐ข๏ธ | ๐ข๏ธ | ๐ข๏ธ | ๐ข๏ธ | ๐ข๏ธ | |
Exists | ๐ข๏ธ | ๐ข๏ธ | ||||
Watch | ๐ข๏ธ | ๐ข๏ธ | ๐ข๏ธ | ๐ด | ||
WatchTree | ||||||
NewLock (Lock/Unlock) | ๐ข๏ธ | ๐ข๏ธ | ||||
List | ๐ข๏ธ | ๐ข๏ธ | ||||
DeleteTree | ||||||
AtomicPut | ๐ข๏ธ | ๐ข๏ธ | ||||
AtomicDelete | ๐ข๏ธ | ๐ข๏ธ |
The store implementations:
The store template:
Limitations
Distributed Key/Value stores often have different concepts for managing and formatting keys and their associated values.
Even though valkeyrie
tries to abstract those stores aiming for some consistency, in some cases it can't be applied easily.
Calls like WatchTree
may return different events (or number of events) depending on the backend
(for now, Etcd
and Consul
will likely return more events than Zookeeper
that you should triage properly).
Contributing
Want to contribute to valkeyrie
?
Take a look at the Contribution Guidelines.
The Maintainers.
Copyright and License
Apache License Version 2.0
Valkeyrie started as a hard fork of the unmaintained libkv.