Documentation
¶
Index ¶
Constants ¶
const Delimiter = '/'
Delimiter separates nested paths in storage.
Variables ¶
var (
// ErrKeyNotFound used when something doesn't exist.
ErrKeyNotFound = errs.Class("key not found")
// ErrEmptyKey is returned when an empty key is used in Put or in CompareAndSwap.
ErrEmptyKey = errs.Class("empty key")
// ErrValueChanged is returned when the current value of the key does not match the old value in CompareAndSwap.
ErrValueChanged = errs.Class("value changed")
)
Functions ¶
Types ¶
type Item ¶
type Item struct {
Key Key
Value Value
IsPrefix bool
}
Item returns Key, Value, IsPrefix.
type Items ¶
type Items []Item
Items keeps all Item.
func (Items) GetKeys ¶
func (items Items) GetKeys() Keys
GetKeys gets all the Keys in []Item and converts them to Keys.
type Key ¶
type Key []byte
Key is the type for the keys in a `Store`.
func (Key) IsZero ¶
func (key Key) IsZero() bool
IsZero returns true if the key struct is a zero value.
func (Key) Less ¶
func (key Key) Less(b Key) bool
Less returns whether key should be sorted before b.
func (Key) MarshalBinary ¶
func (key Key) MarshalBinary() ([]byte, error)
MarshalBinary implements the encoding.BinaryMarshaler interface for the Key type.
type Keys ¶
type Keys []Key
Keys is the type for a slice of keys in a `Store`.
func (Keys) ByteSlices ¶
func (keys Keys) ByteSlices() [][]byte
ByteSlices converts a `Keys` struct to a slice of byte-slices (i.e. `[][]byte`).
type Store ¶
type Store interface {
// Put adds a value to store.
Put(context.Context, Key, Value) error
// Get gets a value to store.
Get(context.Context, Key) (Value, error)
// Delete deletes key and the value.
Delete(context.Context, Key) error
// Range iterates over all items in unspecified order.
// The Key and Value are valid only for the duration of callback.
Range(ctx context.Context, fn func(context.Context, Key, Value) error) error
// CompareAndSwap atomically compares and swaps oldValue with newValue.
CompareAndSwap(ctx context.Context, key Key, oldValue, newValue Value) error
// Close closes the store.
Close() error
}
Store describes key/value stores like redis and boltdb.
type Value ¶
type Value []byte
Value is the type for the values in a `ValueValueStore`.
func (Value) IsZero ¶
func (value Value) IsZero() bool
IsZero returns true if the value struct is a zero value.
func (Value) MarshalBinary ¶
func (value Value) MarshalBinary() ([]byte, error)
MarshalBinary implements the encoding.BinaryMarshaler interface for the Value type.