kv

package
v2.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIteratorClosed = errors.New("store/kv: iterator closed")
View Source
var ErrStateClosed = errors.New("store/kv: state closed")

ErrStateClosed is returned on further calls to states after calling Release().

Functions

This section is empty.

Types

type Iterator

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

Iterator provides a read-only iterator to all the key-value pairs in a KVStore. While the iterator is open the store is read locked, you MUST release the iterator when you are finished with it.

Please note: individual iterators are NOT concurrency safe, though it is safe to have multiple iterators running concurrently.

func (*Iterator) Key

func (i *Iterator) Key() string

Key returns the current iterator key.

func (*Iterator) Next

func (i *Iterator) Next() bool

Next attempts to fetch the next key-value pair, the return value indicates whether another pair remains.

func (*Iterator) Release

func (i *Iterator) Release()

Release will release the store read-lock, and close this iterator.

func (*Iterator) Value

func (i *Iterator) Value(ctx context.Context) ([]byte, error)

Value returns the current iterator value at key.

type KVStore

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

KVStore is a very simple, yet performant key-value store

func New added in v2.0.5

func New(storage storage.Storage) *KVStore

New will simply return a new KVStore instance based on Storage.

func OpenDisk

func OpenDisk(path string, cfg *storage.DiskConfig) (*KVStore, error)

func OpenMemory

func OpenMemory(overwrites bool) *KVStore

func OpenS3

func OpenS3(endpoint string, bucket string, cfg *storage.S3Config) (*KVStore, error)

func OpenStorage

func OpenStorage(storage storage.Storage) (*KVStore, error)

OpenStorage will return a new KVStore instance based on Storage, performing an initial storage.Clean().

func (*KVStore) Close

func (st *KVStore) Close() error

Close will close the underlying storage, the mutex map locking (e.g. RLock(), Lock()) will continue to function.

func (*KVStore) Delete

func (st *KVStore) Delete(ctx context.Context, key string) error

Delete removes value at supplied key from the store.

func (*KVStore) Get

func (st *KVStore) Get(ctx context.Context, key string) ([]byte, error)

Get fetches the bytes for supplied key in the store.

func (*KVStore) GetStream

func (st *KVStore) GetStream(ctx context.Context, key string) (io.ReadCloser, error)

GetStream fetches a ReadCloser for the bytes at the supplied key in the store.

func (*KVStore) Has

func (st *KVStore) Has(ctx context.Context, key string) (bool, error)

Has checks whether the supplied key exists in the store.

func (*KVStore) Iterator

func (st *KVStore) Iterator(ctx context.Context, matchFn func(string) bool) (*Iterator, error)

Iterator returns an Iterator for key-value pairs in the store, using supplied match function

func (*KVStore) Lock

func (st *KVStore) Lock(key string) (unlock func())

Lock acquires a write-lock on supplied key, returning unlock function.

func (*KVStore) Put

func (st *KVStore) Put(ctx context.Context, key string, value []byte) (int, error)

Put places the bytes at the supplied key in the store.

func (*KVStore) PutStream

func (st *KVStore) PutStream(ctx context.Context, key string, r io.Reader) (int64, error)

PutStream writes the bytes from the supplied Reader at the supplied key in the store.

func (*KVStore) RLock

func (st *KVStore) RLock(key string) (runlock func())

RLock acquires a read-lock on supplied key, returning unlock function.

func (*KVStore) Read

func (st *KVStore) Read() *StateRO

Read provides a read-only window to the store, holding it in a read-locked state until release.

func (*KVStore) ReadFn

func (st *KVStore) ReadFn(fn func(*StateRO))

ReadFn provides a read-only window to the store, holding it in a read-locked state until fn return..

func (*KVStore) Update

func (st *KVStore) Update() *StateRW

Update provides a read-write window to the store, holding it in a write-locked state until release.

func (*KVStore) UpdateFn

func (st *KVStore) UpdateFn(fn func(*StateRW))

UpdateFn provides a read-write window to the store, holding it in a write-locked state until fn return.

type StateRO

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

StateRO provides a read-only window to the store. While this state is active during the Read() function window, the entire store will be read-locked. The state is thread-safe for concurrent use UNTIL the moment that your supplied function to Read() returns.

func (*StateRO) Get

func (st *StateRO) Get(ctx context.Context, key string) ([]byte, error)

Get: see KVStore.Get(). Returns error if state already closed.

func (*StateRO) GetStream

func (st *StateRO) GetStream(ctx context.Context, key string) (io.ReadCloser, error)

GetStream: see KVStore.GetStream(). Returns error if state already closed.

func (*StateRO) Has

func (st *StateRO) Has(ctx context.Context, key string) (bool, error)

Has: see KVStore.Has(). Returns error if state already closed.

func (*StateRO) Release

func (st *StateRO) Release()

Release will release the store read-lock, and close this state.

type StateRW

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

StateRW provides a read-write window to the store. While this state is active during the Update() function window, the entire store will be locked. The state is thread-safe for concurrent use UNTIL the moment that your supplied function to Update() returns.

func (*StateRW) Delete

func (st *StateRW) Delete(ctx context.Context, key string) error

Delete: see KVStore.Delete(). Returns error if state already closed.

func (*StateRW) Get

func (st *StateRW) Get(ctx context.Context, key string) ([]byte, error)

Get: see KVStore.Get(). Returns error if state already closed.

func (*StateRW) GetStream

func (st *StateRW) GetStream(ctx context.Context, key string) (io.ReadCloser, error)

GetStream: see KVStore.GetStream(). Returns error if state already closed.

func (*StateRW) Has

func (st *StateRW) Has(ctx context.Context, key string) (bool, error)

Has: see KVStore.Has(). Returns error if state already closed.

func (*StateRW) Put

func (st *StateRW) Put(ctx context.Context, key string, value []byte) (int, error)

Put: see KVStore.Put(). Returns error if state already closed.

func (*StateRW) PutStream

func (st *StateRW) PutStream(ctx context.Context, key string, r io.Reader) (int64, error)

PutStream: see KVStore.PutStream(). Returns error if state already closed.

func (*StateRW) Release

func (st *StateRW) Release()

Release will release the store lock, and close this state.

Jump to

Keyboard shortcuts

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