natskv

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

Valkeyrie NatsKV

GoDoc Build Status

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 interface.

Calls NatsKV
Put 🟢️
Get 🟢️
Delete 🟢️
Exists 🟢️
Watch 🟢️
WatchTree 🟢️
NewLock (Lock/Unlock)
List 🟢️
DeleteTree 🟢️
AtomicPut 🟢️
AtomicDelete 🟢️

Supported Versions

nats-server versions >= 2.10.

Examples

package main

import (
	"context"
	"log"

	"github.com/kvtools/valkeyrie"
	"github.com/ozanturksever/natskv"
)

func main() {
	ctx := context.Background()

	config := &natskv.Config{
        Bucket: "example",
		EncodeKey: false,
	}

	kv, err := valkeyrie.NewStore(ctx, natskv.StoreName, []string{ "nats://localhost:4222"}, 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)
	}
}

Documentation

Index

Constants

View Source
const StoreName = "natskv"

Variables

This section is empty.

Functions

func New

func New(_ context.Context, endpoints []string, options *Config) (store.Store, error)

Types

type Config

type Config struct {
	Bucket    string
	EncodeKey bool
	Nc        *nats.Conn
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func (*Store) AtomicDelete

func (s *Store) AtomicDelete(ctx context.Context, key string, previous *store.KVPair) (bool, error)

func (*Store) AtomicPut

func (s *Store) AtomicPut(ctx context.Context, key string, value []byte, previous *store.KVPair, opts *store.WriteOptions) (bool, *store.KVPair, error)

AtomicPut puts a value at "key" if the key has not been modified in the meantime, throws an error if this is the case.

func (*Store) Close

func (s *Store) Close() error

Close closes the client connection.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

func (*Store) DeleteTree

func (s *Store) DeleteTree(ctx context.Context, directory string) error

func (*Store) Exists

func (s *Store) Exists(ctx context.Context, key string, _ *store.ReadOptions) (bool, error)

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string, _ *store.ReadOptions) (pair *store.KVPair, err error)

func (*Store) List

func (s *Store) List(ctx context.Context, directory string, opts *store.ReadOptions) ([]*store.KVPair, error)

func (*Store) NewLock

func (s *Store) NewLock(_ context.Context, key string, opts *store.LockOptions) (lock store.Locker, err error)

func (*Store) Put

func (s *Store) Put(ctx context.Context, key string, value []byte, opts *store.WriteOptions) error

func (*Store) Watch

func (s *Store) Watch(ctx context.Context, key string, _ *store.ReadOptions) (<-chan *store.KVPair, error)

func (*Store) WatchTree

func (s *Store) WatchTree(ctx context.Context, directory string, opts *store.ReadOptions) (<-chan []*store.KVPair, error)

Jump to

Keyboard shortcuts

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