store

package
v0.0.0-...-eafe4e1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package store is a thread-safe key/value store facade.

The key syntax is assumed to be "path-like" hierarchy such as /howdy/doody. The error strategy for the package is to pass all underlying backend errors out as the error for the io.Reader.Read function.

The returned io.Readers' Read function will lazy load the backend's data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableEtcdDebug

func EnableEtcdDebug()

EnableEtcdDebug turns on cURL debug logging for the etcd client

func NewKeyNotFound

func NewKeyNotFound(key string) error

NewKeyNotFound constructs and formats KeyNotFound

Types

type EtcdStore

type EtcdStore struct {
	// mutex is used to synchronize client access
	*sync.Mutex
	// client is the Etcd client connection
	client.KeysAPI
	// timeout is the etcd client request timeout
	Timeout time.Duration
}

EtcdStore implements the Store interface and can use directory like paths as keys.

func NewEtcdStore

func NewEtcdStore(machines []string, timeout time.Duration) (*EtcdStore, error)

NewEtcdStore constructs an EtcdStore using the given machine list

func (*EtcdStore) Delete

func (e *EtcdStore) Delete(key string, recurse bool) error

Delete removes the specified key. Set recurse to true to delete recursively

func (*EtcdStore) Get

func (e *EtcdStore) Get(key string) io.Reader

Get returns an io.Reader for a single existing Etcd key. The key's value is not loaded until Read is called in the io.Reader

func (*EtcdStore) GetMulti

func (e *EtcdStore) GetMulti(prefix string) io.Reader

GetMulti returns all Etcd values whose keys are prefixed with prefix. The returned io.Reader has all values concatenated as a single output using io.MultiReader. Conceptually, this will return all values for a "directory"-like key. Each io.Reader is lazy loaded at .Read() call.

func (*EtcdStore) GetMultiMap

func (e *EtcdStore) GetMultiMap(prefix string) (map[string]io.Reader, error)

GetMultiMap returns a map of all keys prefixed with prefix whose values are io.Readers. Note that all key-value pairs are loaded and cached during this call.

func (*EtcdStore) Keys

func (e *EtcdStore) Keys(prefix string) ([]string, error)

Keys returns all keys prefixed with string as a slice of strings. Internally, this will recursively get all Etcd keys from a directory.

func (*EtcdStore) Mkdir

func (e *EtcdStore) Mkdir(path string, ttl time.Duration) error

Mkdir will create a directory with the specified path and ttl

func (*EtcdStore) Set

func (e *EtcdStore) Set(key string, value []byte, ttl time.Duration) error

Set will set a single Etcd key to value with a ttl. If the ttl is zero then no ttl will be set. Ttls in etcd are in seconds and must be at least 1

type KeyNotFound

type KeyNotFound struct {
	Key string
	// contains filtered or unexported fields
}

KeyNotFound is the error returned when the MemStore is not able to find the key.

func (*KeyNotFound) Error

func (e *KeyNotFound) Error() string

Error returns the key string that was not able to be found

type MemStore

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

MemStore is an in-memory implementation of the Store interface using a map.

func NewMemStore

func NewMemStore() *MemStore

NewMemStore constructs a thread-safe in memory key-value store implemented with a map[string][string].

func (*MemStore) Delete

func (m *MemStore) Delete(key string, recurse bool) error

Delete removes the specified key. Set recurse to true to delete recursively

func (*MemStore) Get

func (m *MemStore) Get(key string) io.Reader

Get returns an io.Reader associated with a single key in the store.

func (*MemStore) GetMulti

func (m *MemStore) GetMulti(prefix string) io.Reader

GetMulti returns an io.MultiReader of all keys prefixed by prefix.

func (*MemStore) GetMultiMap

func (m *MemStore) GetMultiMap(prefix string) (map[string]io.Reader, error)

GetMultiMap returns a key-value map of all keys prefixed by prefix

func (*MemStore) Keys

func (m *MemStore) Keys(prefix string) ([]string, error)

Keys returns all keys in the internal map that are prefixed with prefix

func (*MemStore) Mkdir

func (m *MemStore) Mkdir(path string, ttl time.Duration) error

Mkdir simply calls Set with an empty value

func (*MemStore) Set

func (m *MemStore) Set(key string, value []byte, ttl time.Duration) error

Set will add an entry to the internal map and set a time-to-live using a time.Timer if the duration is greater than 0.

type Store

type Store interface {
	// Get returns an io.Reader for key
	Get(key string) io.Reader
	// Delete removes the specified key. Set recurse to true to delete recursively
	Delete(key string, recurse bool) error
	// GetMulti retrieves all keys with prefix.  The io.Reader returns all values
	// concatenated back to back.  See the Example in the tests to show how to
	// use this with JSON data.  Lazy loaded and if any errors occur they are
	// propagated through the io.Readers Read().
	GetMulti(prefix string) io.Reader
	// GetMultiMap retrieves all keys with prefix.  The return is a map of keys to
	// io.Reader values. Error is propagated from underlying backend.
	GetMultiMap(prefix string) (map[string]io.Reader, error)
	// Set will store a key-value pair into the store.  If the ttl value is 0,
	// then the value will never timeout. The returned error will be nil on
	// success or come from the underlying implementation.
	Set(key string, value []byte, ttl time.Duration) error
	// Mkdir creates a directory or bucket with the specified path and ttl
	Mkdir(path string, ttl time.Duration) error
	// Keys returns all keys prefixed by prefix. error returned is specific to
	// underlying store implementation.
	Keys(prefix string) ([]string, error)
}

Store is a key/value interface with "path-like" key hierarchies.

Jump to

Keyboard shortcuts

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