kv

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: May 8, 2022 License: MIT Imports: 5 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")

Functions

This section is empty.

Types

type KVIterator

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

KVIterator 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 (*KVIterator) Key

func (i *KVIterator) Key() string

Key returns the next key from the store

func (*KVIterator) Next

func (i *KVIterator) Next() bool

Next attempts to set the next key-value pair, the return value is if there was another pair remaining

func (*KVIterator) Release

func (i *KVIterator) Release()

Release releases the KVIterator and KVStore's read lock

func (*KVIterator) Value

func (i *KVIterator) Value() ([]byte, error)

Value returns the next value from the KVStore

type KVStore

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

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

func OpenBlock

func OpenBlock(path string, cfg *storage.BlockConfig) (*KVStore, error)

func OpenFile

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

func OpenStorage

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

func (*KVStore) Close added in v1.3.0

func (st *KVStore) Close() error

Close will close the underlying storage, the mutex map locking (e.g. RLock(), Lock() will still work).

func (*KVStore) Delete

func (st *KVStore) Delete(key string) error

Delete removes the supplied key-value pair from the store

func (*KVStore) Get

func (st *KVStore) Get(key string) ([]byte, error)

Get fetches the bytes for supplied key in the store

func (*KVStore) GetStream

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

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

func (*KVStore) Has

func (st *KVStore) Has(key string) (bool, error)

Has checks whether the supplied key exists in the store

func (*KVStore) Iterator

func (st *KVStore) Iterator(matchFn func(string) bool) (*KVIterator, error)

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

func (*KVStore) Lock added in v1.2.0

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(key string, value []byte) error

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

func (*KVStore) PutStream

func (st *KVStore) PutStream(key string, r io.Reader) error

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

func (*KVStore) RLock added in v1.2.0

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 added in v1.1.4

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 added in v1.1.4

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, then the state has zero guarantees

func (*StateRO) Get

func (st *StateRO) Get(key string) ([]byte, error)

func (*StateRO) GetStream

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

func (*StateRO) Has

func (st *StateRO) Has(key string) (bool, error)

func (*StateRO) Release added in v1.1.4

func (st *StateRO) Release()

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, then the state has zero guarantees

func (*StateRW) Delete

func (st *StateRW) Delete(key string) error

func (*StateRW) Get

func (st *StateRW) Get(key string) ([]byte, error)

func (*StateRW) GetStream

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

func (*StateRW) Has

func (st *StateRW) Has(key string) (bool, error)

func (*StateRW) Put

func (st *StateRW) Put(key string, value []byte) error

func (*StateRW) PutStream

func (st *StateRW) PutStream(key string, r io.Reader) error

func (*StateRW) Release added in v1.1.4

func (st *StateRW) Release()

Jump to

Keyboard shortcuts

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