• Stars
    star
    170
  • Rank 223,357 (Top 5 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Distributed Key/Value Store Abstraction Library written in Go

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.