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 ¶
- func EnableEtcdDebug()
- func NewKeyNotFound(key string) error
- type EtcdStore
- func (e *EtcdStore) Delete(key string, recurse bool) error
- func (e *EtcdStore) Get(key string) io.Reader
- func (e *EtcdStore) GetMulti(prefix string) io.Reader
- func (e *EtcdStore) GetMultiMap(prefix string) (map[string]io.Reader, error)
- func (e *EtcdStore) Keys(prefix string) ([]string, error)
- func (e *EtcdStore) Mkdir(path string, ttl time.Duration) error
- func (e *EtcdStore) Set(key string, value []byte, ttl time.Duration) error
- type KeyNotFound
- type MemStore
- func (m *MemStore) Delete(key string, recurse bool) error
- func (m *MemStore) Get(key string) io.Reader
- func (m *MemStore) GetMulti(prefix string) io.Reader
- func (m *MemStore) GetMultiMap(prefix string) (map[string]io.Reader, error)
- func (m *MemStore) Keys(prefix string) ([]string, error)
- func (m *MemStore) Mkdir(path string, ttl time.Duration) error
- func (m *MemStore) Set(key string, value []byte, ttl time.Duration) error
- type Store
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 ¶
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 ¶
NewEtcdStore constructs an EtcdStore using the given machine list
func (*EtcdStore) Delete ¶
Delete removes the specified key. Set recurse to true to delete recursively
func (*EtcdStore) Get ¶
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 ¶
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 ¶
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 ¶
Keys returns all keys prefixed with string as a slice of strings. Internally, this will recursively get all Etcd keys from a directory.
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 ¶
Delete removes the specified key. Set recurse to true to delete recursively
func (*MemStore) GetMultiMap ¶
GetMultiMap returns a key-value map of all keys prefixed by prefix
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.