kv

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Get a spefic key.  Will use a codec to deserialise key to appropriate type.
	Get(ctx context.Context, key string) (interface{}, error)

	// CAS stands for Compare-And-Swap.  Will call provided callback f with the
	// current value of the key and allow callback to return a different value.
	// Will then attempt to atomically swap the current value for the new value.
	// If that doesn't succeed will try again - callback will be called again
	// with new value etc.  Guarantees that only a single concurrent CAS
	// succeeds.  Callback can return nil to indicate it is happy with existing
	// value.
	CAS(ctx context.Context, key string, f func(in interface{}) (out interface{}, retry bool, err error)) error

	// WatchKey calls f whenever the value stored under key changes.
	WatchKey(ctx context.Context, key string, f func(interface{}) bool)

	// WatchPrefix calls f whenever any value stored under prefix changes.
	WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool)
}

Client is a high-level client for key-value stores (such as Etcd and Consul) that exposes operations such as CAS and Watch which take callbacks. It also deals with serialisation by using a Codec and having a instance of the the desired type passed in to methods ala json.Unmarshal.

func NewClient

func NewClient(cfg Config, codec codec.Codec) (Client, error)

NewClient creates a new Client (consul, etcd or inmemory) based on the config, encodes and decodes data for storage using the codec.

func PrefixClient

func PrefixClient(client Client, prefix string) Client

PrefixClient takes a KVClient and forces a prefix on all its operations.

type Config

type Config struct {
	Store  string        `yaml:"store,omitempty"`
	Consul consul.Config `yaml:"consul,omitempty"`
	Etcd   etcd.Config   `yaml:"etcd,omitempty"`
	Prefix string        `yaml:"prefix,omitempty"`

	Mock Client
}

Config is config for a KVStore currently used by ring and HA tracker, where store can be consul or inmemory.

func (*Config) RegisterFlagsWithPrefix

func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet. If prefix is an empty string we will register consul flags with no prefix and the store flag with the prefix ring, so ring.store. For everything else we pass the prefix to the Consul flags. If prefix is not an empty string it should end with a period.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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