Categorygithub.com/nuts-foundation/go-stoabs
modulepackage
1.9.0
Repository: https://github.com/nuts-foundation/go-stoabs.git
Documentation: pkg.go.dev

# README

Golang Storage Abstraction (go-stoabs)

BBolt

Redis

When creating a Redis KVStore it tests the connection using Redis' PING command.

Due to the simple API of the library, the Redis adapter only supports reading/writing byte arrays. The behavior when reading any other Redis type (e.g. a list or set) is undefined.

Transaction Isolation

Redis doesn't have actual transactions, so this library simulates them by using the MULTI/EXEC/DISCARD commands. That way all commands are guaranteed to be executed atomically.

As a consequence, a value that hasn't been committed yet can't be read. In other words, don't try to read a value from a key that was written to in the same transaction. Subsequently, changes from other writers (from the same process or remote) are reflected immediately in the current transaction: if a key is read twice, there's no guarantee the returned value will be equal.

If the application requires exclusive write access to a store it can lock the database, to assert there are no other active writers:

store.Write(func (tx stoabs.WriteTx) error { 
	// do something with tx
}, stoabs.WithWriteLock())

The lock is released when the transaction is committed or rolled back. The lock is subject to the prefix (CreateRedisStore(prefix string, ...)) the store was created with, meaning other stores with the same prefix will have the same lock.

Redis locks are implemented using (Redsync)[https://github.com/go-redsync/redsync].

Unsupported features

  • Clustering

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

AfterCommit specifies a function that will be called after a transaction is successfully committed.
DatabaseError wraps the given error in ErrDatabase if it isn't already in the error chain.
DefaultConfig returns the default configuration.
NewErrorWriter returns a Writer that will return the error for every method.
NewHashKey creates a new HashKey from bytes.
NewMockKVStore creates a new mock instance.
NewMockReader creates a new mock instance.
NewMockReadTx creates a new mock instance.
NewMockStore creates a new mock instance.
NewMockTxOption creates a new mock instance.
NewMockWriter creates a new mock instance.
NewMockWriteTx creates a new mock instance.
OnRollback specifies a function that will be called after a transaction is successfully rolled back.
WithLockAcquireTimeout overrides the default timeout for acquiring a lock.
WithLogger overrides the default logger.
WithNoSync specifies that the database should not flush its data to disk.
WithWriteLock is a transaction option that acquires a write lock for the entire store, making sure there are no concurrent writeable transactions.

# Constants

No description provided by the author

# Variables

ErrCommitFailed is returned when the commit of transaction fails.
ErrKeyNotFound is returned when the requested key does not exist.
ErrStoreIsClosed is returned when an operation is executed on a closed store.

# Structs

AfterCommitOption see AfterCommit.
Config specifies the configuration for a KVStore.
ErrDatabase signals that the wrapped error is related to database access, or due to context cancellation/timeout.
MockKVStore is a mock of KVStore interface.
MockKVStoreMockRecorder is the mock recorder for MockKVStore.
MockReader is a mock of Reader interface.
MockReaderMockRecorder is the mock recorder for MockReader.
MockReadTx is a mock of ReadTx interface.
MockReadTxMockRecorder is the mock recorder for MockReadTx.
MockStore is a mock of Store interface.
MockStoreMockRecorder is the mock recorder for MockStore.
MockTxOption is a mock of TxOption interface.
MockTxOptionMockRecorder is the mock recorder for MockTxOption.
MockWriter is a mock of Writer interface.
MockWriterMockRecorder is the mock recorder for MockWriter.
MockWriteTx is a mock of WriteTx interface.
MockWriteTxMockRecorder is the mock recorder for MockWriteTx.
NilReader is a shelfReader that always returns nil.
OnRollbackOption see OnRollback.
ShelfStats contains statistics about a shelf.
WriteLockOption see WithWriteLock.

# Interfaces

Key is an abstraction for a key in a key/value pair.
KVStore defines the interface for a key-value store.
Reader is used to read from a shelf.
ReadTx is used to read from a KVStore.
No description provided by the author
TxOption holds options for store transactions.
Writer is used to write to a shelf.
WriteTx is used to write to a KVStore.

# Type aliases

BytesKey is a type helper for a byte slice as Key.
CallerFn is the function type which is called for each key value pair when using Iterate() or Range().
HashKey is a type helper for a 256 bits hash as Key.
No description provided by the author
Uint32Key is a type helper for a uint32 as Key.