simplekv

package module
v0.0.0-...-dac8ed1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2018 License: LGPL-3.0 Imports: 3 Imported by: 0

README

simplekv: a simple key-value store with multiple backends

This repository provides a naive key-value store with Postgres, MongoDB and in-memory backend implementations.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is the error cause used when an identity cannot be
	// found in storage.
	ErrNotFound = errgo.New("not found")

	// ErrDuplicateKey is the error cause used when SetKeyOnce
	// tries to set a duplicate key.
	ErrDuplicateKey = errgo.New("duplicate key")
)

Functions

func KeyNotFoundError

func KeyNotFoundError(key string) error

KeyNotFoundError creates a new error with a cause of ErrNotFound and an appropriate message.

func SetKeyOnce

func SetKeyOnce(ctx context.Context, kv Store, key string, value []byte, expire time.Time) error

SetKeyOnce is like Store.Set except that if the key already has a value associated with it it returns an error with a cause of ErrDuplicateKey.

Types

type Store

type Store interface {
	// Context returns a context that is suitable for passing to the
	// other Store methods. Store methods called with
	// such a context will be sequentially consistent; for example, a
	// value that is set in Set will immediately be available from
	// Get.
	//
	// The returned close function must be called when the returned
	// context will no longer be used, to allow for any required
	// cleanup.
	Context(ctx context.Context) (_ context.Context, close func())

	// Get retrieves the value associated with the given key. If
	// there is no such key an error with a cause of ErrNotFound will
	// be returned.
	Get(ctx context.Context, key string) ([]byte, error)

	// Set updates the given key to have the specified value.
	//
	// If the expire time is non-zero then the entry may be garbage
	// collected at some point after that time. Clients should not
	// rely on the value being removed at the given time.
	Set(ctx context.Context, key string, value []byte, expire time.Time) error

	// Update updates the value for the given key. The getVal
	// function is called with the old value of the key and should
	// return the new value, which will be updated atomically;
	// getVal may be called several times, so should not have
	// side-effects.
	//
	// If an entry for the given key did not previously exist, old
	// will be nil.
	//
	// If getVal returns an error, it will be returned by Update with
	// its cause unchanged.
	//
	// If the expire time is non-zero then the entry may be garbage
	// collected at some point after that time. Clients should not
	// rely on the value being removed at the given time.
	Update(ctx context.Context, key string, expire time.Time, getVal func(old []byte) ([]byte, error)) error
}

Store holds the interface implemented by the various backend implementations.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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