Skip to content

Distributed Key/Value Store Abstraction Library written in Go.

License

Notifications You must be signed in to change notification settings

traefik/valkeyrie

 
 

Repository files navigation

golangci-lint logo

Valkeyrie

Distributed Key/Value Store Abstraction Library

Valkeyrie

Go Reference Build and test Go Report Card

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.

About

Distributed Key/Value Store Abstraction Library written in Go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.5%
  • Makefile 0.5%