valkeyrie

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 19

README

Valkeyrie

GoDoc Build Status 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.

Apache License Version 2.0

Valkeyrie started as a hard fork of the unmaintained libkv.

Documentation

Overview

Package valkeyrie Distributed Key/Value Store Abstraction Library written in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Constructors added in v1.0.0

func Constructors() []string

Constructors returns a sorted list of the names of the registered constructors.

func NewStore

func NewStore(ctx context.Context, storeName string, endpoints []string, options Config) (store.Store, error)

NewStore creates a new store instance.

func Register added in v1.0.0

func Register(name string, cttr Constructor)

Register makes a store constructor available by the provided name. If Register is called twice with the same name or if constructor is nil, it panics.

func Unregister added in v1.0.0

func Unregister(storeName string)

Unregister Unregisters a store.

func UnregisterAllConstructors added in v1.0.0

func UnregisterAllConstructors()

UnregisterAllConstructors Unregisters all stores.

Types

type Config added in v1.0.0

type Config any

Config the raw type of the store configurations.

type Constructor added in v1.0.0

type Constructor func(ctx context.Context, endpoints []string, options Config) (store.Store, error)

Constructor The signature of a store constructor.

Directories

Path Synopsis
Package store contains KV store backends.
Package store contains KV store backends.
Package testsuite the valkeyrie tests suite.
Package testsuite the valkeyrie tests suite.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL