Documentation ¶
Overview ¶
Package kv implements a simple key/value store with backing drivers. Each storage system can operate on value types in an independent way, allowing for a variety of schemas to be represented.
Index ¶
- Variables
- type Client
- func (c *Client) CASBytes(ctx context.Context, key string, nonce, origValue, value []byte) ([]byte, error)
- func (c *Client) CASFloat64(ctx context.Context, key string, nonce []byte, origValue, value float64) ([]byte, error)
- func (c *Client) CASInt64(ctx context.Context, key string, nonce []byte, origValue, value int64) ([]byte, error)
- func (c *Client) CASString(ctx context.Context, key string, nonce []byte, origValue, value string) ([]byte, error)
- func (c *Client) CASUint64(ctx context.Context, key string, nonce []byte, origValue, value uint64) ([]byte, error)
- func (c *Client) CreateBytes(ctx context.Context, key string, value []byte) ([]byte, error)
- func (c *Client) CreateFloat64(ctx context.Context, key string, out float64) ([]byte, error)
- func (c *Client) CreateInt64(ctx context.Context, key string, out int64) ([]byte, error)
- func (c *Client) CreateString(ctx context.Context, key, value string) ([]byte, error)
- func (c *Client) CreateUint64(ctx context.Context, key string, out uint64) ([]byte, error)
- func (c *Client) Delete(ctx context.Context, key string, nonce []byte) error
- func (c *Client) GetBytes(ctx context.Context, key string) ([]byte, []byte, error)
- func (c *Client) GetFloat64(ctx context.Context, key string) (float64, []byte, error)
- func (c *Client) GetInt64(ctx context.Context, key string) (int64, []byte, error)
- func (c *Client) GetString(ctx context.Context, key string) (string, []byte, error)
- func (c *Client) GetUint64(ctx context.Context, key string) (uint64, []byte, error)
- func (c *Client) SetBytes(ctx context.Context, key string, value []byte) ([]byte, error)
- func (c *Client) SetFloat64(ctx context.Context, key string, value float64) ([]byte, error)
- func (c *Client) SetInt64(ctx context.Context, key string, out int64) ([]byte, error)
- func (c *Client) SetString(ctx context.Context, key, value string) ([]byte, error)
- func (c *Client) SetUint64(ctx context.Context, key string, out uint64) ([]byte, error)
- type DBDriver
- func (db *DBDriver) CAS(ctx context.Context, member, key string, nonce, origValue, value []byte) ([]byte, error)
- func (db *DBDriver) Create(ctx context.Context, member, key string, value []byte) ([]byte, error)
- func (db *DBDriver) Delete(ctx context.Context, member, key string, nonce []byte) error
- func (db *DBDriver) Get(ctx context.Context, member, key string) ([]byte, []byte, error)
- func (db *DBDriver) Set(ctx context.Context, member, key string, value []byte) ([]byte, error)
- type Driver
- type MemoryDriver
- func (md *MemoryDriver) CAS(ctx context.Context, member, key string, origNonce, origValue, value []byte) ([]byte, error)
- func (md *MemoryDriver) Create(ctx context.Context, member, key string, value []byte) ([]byte, error)
- func (md *MemoryDriver) Delete(ctx context.Context, member, key string, nonce []byte) error
- func (md *MemoryDriver) Get(ctx context.Context, member, key string) ([]byte, []byte, error)
- func (md *MemoryDriver) Set(ctx context.Context, member, key string, value []byte) ([]byte, error)
- type MemoryTable
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnmarshal is returned when unmarshaling to a native type failed. ErrUnmarshal = errors.New("unmarshaling failed") // ErrMarshal is returned when marshaling from a native type failed. ErrMarshal = errors.New("marshaling failed") )
var ( // ErrAlreadySet refers to create operations that would overwrite an intended value. ErrAlreadySet = errors.New("value is already set") // ErrInvalidType covers types that are invalid for exchange with this library. ErrInvalidType = errors.New("invalid type in k/v operation") // ErrUnsetValue is returned when nil is sent because the value is unset. ErrUnsetValue = errors.New("unset value") // ErrNotEqual indicates that a CAS operation failed its compare. ErrNotEqual = errors.New("original value is not equal") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the typical end-user entry into the k/v system. This allows for the standard operations on drivers.
func (*Client) CASBytes ¶
func (c *Client) CASBytes(ctx context.Context, key string, nonce, origValue, value []byte) ([]byte, error)
CASBytes implements compare-and-swap semantics with marshaled data.
func (*Client) CASFloat64 ¶
func (c *Client) CASFloat64(ctx context.Context, key string, nonce []byte, origValue, value float64) ([]byte, error)
CASFloat64 compares and swaps float64s.
func (*Client) CASInt64 ¶
func (c *Client) CASInt64(ctx context.Context, key string, nonce []byte, origValue, value int64) ([]byte, error)
CASInt64 compares and swaps uint64 values.
func (*Client) CASString ¶
func (c *Client) CASString(ctx context.Context, key string, nonce []byte, origValue, value string) ([]byte, error)
CASString compares and swaps strings.
func (*Client) CASUint64 ¶
func (c *Client) CASUint64(ctx context.Context, key string, nonce []byte, origValue, value uint64) ([]byte, error)
CASUint64 compares and swaps uint64 values.
func (*Client) CreateBytes ¶
CreateBytes creates a key for the k/v store as raw bytes.
func (*Client) CreateFloat64 ¶
CreateFloat64 creates a float64 where there wasn't one before.
func (*Client) CreateInt64 ¶
CreateInt64 creates a new key as int64.
func (*Client) CreateString ¶
CreateString creates a string where there wasn't one before.
func (*Client) CreateUint64 ¶
CreateUint64 creates a new key as uint64.
func (*Client) Delete ¶
Delete deletes any key, regardless of type; pass a nonce to delete conditionally.
func (*Client) GetBytes ¶
GetBytes retrieves a key for the k/v store as marshaled data. The `out` argument must be a non-nil byte array.
func (*Client) GetFloat64 ¶
GetFloat64 retrieves the marshaled data for key and then converts it to float64.
func (*Client) GetInt64 ¶
GetInt64 retrieves the marshaled data for key and then converts it to int64.
func (*Client) GetString ¶
GetString retrieves the marshaled data for key and then converts it to string.
func (*Client) GetUint64 ¶
GetUint64 retrieves the marshaled data for key and then converts it to uint64.
func (*Client) SetFloat64 ¶
SetFloat64 sets a float64 to a key.
type DBDriver ¶
type DBDriver struct {
// contains filtered or unexported fields
}
DBDriver is a database driver.
func (*DBDriver) CAS ¶
func (db *DBDriver) CAS(ctx context.Context, member, key string, nonce, origValue, value []byte) ([]byte, error)
CAS implements a compare-and-swap operation.
type Driver ¶
type Driver interface { Create(context.Context, string, string, []byte) ([]byte, error) Delete(context.Context, string, string, []byte) error Get(context.Context, string, string) ([]byte, []byte, error) Set(context.Context, string, string, []byte) ([]byte, error) CAS(context.Context, string, string, []byte, []byte, []byte) ([]byte, error) }
Driver describes the driver implementation of a k/v store's operations.
func NewDBDriver ¶
NewDBDriver creates a new DBDriver from a db handle.
func NewMemoryDriver ¶
func NewMemoryDriver(preinit MemoryTable) Driver
NewMemoryDriver returns a Driver that is basically a locked map. You can provide a series of initial values or just pass nil to get an empty set.
type MemoryDriver ¶
type MemoryDriver struct {
// contains filtered or unexported fields
}
MemoryDriver implements a very basic key/value store over a map.
func (*MemoryDriver) CAS ¶
func (md *MemoryDriver) CAS(ctx context.Context, member, key string, origNonce, origValue, value []byte) ([]byte, error)
CAS implements compare-and-swap for the k/v store.
func (*MemoryDriver) Create ¶
func (md *MemoryDriver) Create(ctx context.Context, member, key string, value []byte) ([]byte, error)
Create creates a key
type MemoryTable ¶
MemoryTable is the underlying data structure used to manage memory in the MemoryDriver.