https://github.com/kvtools/consul
Valkeyrie: consul
https://github.com/kvtools/consul
consul go golang kv-store valkeyrie
Last synced: 3 months ago
JSON representation
Valkeyrie: consul
- Host: GitHub
- URL: https://github.com/kvtools/consul
- Owner: kvtools
- License: apache-2.0
- Created: 2022-09-07T16:25:07.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-27T22:40:05.000Z (about 1 year ago)
- Last Synced: 2025-05-05T21:26:16.923Z (about 1 year ago)
- Topics: consul, go, golang, kv-store, valkeyrie
- Language: Go
- Homepage:
- Size: 144 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Valkeyrie Consul
[](https://godoc.org/github.com/kvtools/consul)
[](https://github.com/kvtools/consul/actions/workflows/build.yml)
[](https://goreportcard.com/report/github.com/kvtools/consul)
[`valkeyrie`](https://github.com/kvtools/valkeyrie) provides a Go native library to store metadata using Distributed Key/Value stores (or common databases).
## Compatibility
A **storage backend** in `valkeyrie` implements (fully or partially) the [Store](https://github.com/kvtools/valkeyrie/blob/master/store/store.go#L69) interface.
| Calls | Consul |
|-----------------------|:------:|
| Put | 🟢️ |
| Get | 🟢️ |
| Delete | 🟢️ |
| Exists | 🟢️ |
| Watch | 🟢️ |
| WatchTree | 🟢️ |
| NewLock (Lock/Unlock) | 🟢️ |
| List | 🟢️ |
| DeleteTree | 🟢️ |
| AtomicPut | 🟢️ |
| AtomicDelete | 🟢️ |
## Supported Versions
Consul versions >= `0.5.1` because it uses Sessions with `Delete` behavior for the use of `TTLs` (mimics zookeeper's Ephemeral node support).
If you don't plan to use `TTLs`: you can use Consul version `0.4.0+`.
## Examples
```go
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")
}
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)
}
}
```