storage

package
v5.1.6-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtomicStorage

type AtomicStorage interface {
	// Get returns value by key. ok value indicates whether passed key is
	// present in the storage. err indicates storage error.
	Get(key string) (value string, ok bool, err error)
	// GetByKeyPrefix returns list of values which keys has given prefix.
	GetByKeyPrefix(prefix string) (values []string, err error)
	// Put uncoditionally writes value by key in storage, err is not nil in
	// case of storage error.
	Put(key string, value string) (err error)
	// PutIfAbsent writes value if and only if key is absent in storage. ok is
	// true if key was absent and false otherwise. err indicates storage error.
	PutIfAbsent(key string, value string) (ok bool, err error)
	// CompareAndSwap atomically replaces prevValue by newValue. If ok flag is
	// true and err is nil then operation was successful. If err is nil and ok
	// is false then operation failed because prevValue is not equal to current
	// value. err indicates storage error.
	CompareAndSwap(key string, prevValue string, newValue string) (ok bool, err error)
	// Delete removes value by key
	Delete(key string) (err error)

	StartTransaction(conditionKeys []string) (transaction Transaction, err error)
	CompleteTransaction(transaction Transaction, update []KeyValueData) (ok bool, err error)
	ExecuteTransaction(request CASRequest) (ok bool, err error)
}

AtomicStorage is an interface to key-value storage with atomic operations.

type CASRequest

type CASRequest struct {
	RetryTillSuccessOrError bool
	Update                  UpdateFunc
	ConditionKeys           []string
}

type KeyValueData

type KeyValueData struct {
	Key     string
	Value   string
	Present bool
}

type MemoryStorage

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

func NewMemStorage

func NewMemStorage() (storage *MemoryStorage)

NewMemStorage returns new in-memory atomic storage implementation

func (*MemoryStorage) Clear

func (storage *MemoryStorage) Clear() (err error)

func (*MemoryStorage) CompareAndSwap

func (storage *MemoryStorage) CompareAndSwap(key, prevValue, newValue string) (ok bool, err error)

func (*MemoryStorage) CompleteTransaction

func (storage *MemoryStorage) CompleteTransaction(transaction Transaction, update []KeyValueData) (ok bool, err error)

func (*MemoryStorage) Delete

func (storage *MemoryStorage) Delete(key string) (err error)

func (*MemoryStorage) ExecuteTransaction

func (storage *MemoryStorage) ExecuteTransaction(request CASRequest) (ok bool, err error)

func (*MemoryStorage) Get

func (storage *MemoryStorage) Get(key string) (value string, ok bool, err error)

func (*MemoryStorage) GetByKeyPrefix

func (storage *MemoryStorage) GetByKeyPrefix(prefix string) (values []string, err error)

func (*MemoryStorage) Put

func (storage *MemoryStorage) Put(key, value string) (err error)

func (*MemoryStorage) PutIfAbsent

func (storage *MemoryStorage) PutIfAbsent(key, value string) (ok bool, err error)

func (*MemoryStorage) StartTransaction

func (storage *MemoryStorage) StartTransaction(conditionKeys []string) (transaction Transaction, err error)

type PrefixedAtomicStorage

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

PrefixedAtomicStorage is decorator for atomic storage which adds a prefix to the storage keys.

func NewPrefixedAtomicStorage

func NewPrefixedAtomicStorage(atomicStorage AtomicStorage, prefix string) *PrefixedAtomicStorage

It is recommended to use this function to create a PrefixedAtomicStorage

func (*PrefixedAtomicStorage) CompareAndSwap

func (storage *PrefixedAtomicStorage) CompareAndSwap(key string, prevValue string, newValue string) (ok bool, err error)

CompareAndSwap is implementation of AtomicStorage.CompareAndSwap

func (*PrefixedAtomicStorage) CompleteTransaction

func (storage *PrefixedAtomicStorage) CompleteTransaction(transaction Transaction, update []KeyValueData) (ok bool, err error)

func (*PrefixedAtomicStorage) Delete

func (storage *PrefixedAtomicStorage) Delete(key string) (err error)

func (*PrefixedAtomicStorage) ExecuteTransaction

func (storage *PrefixedAtomicStorage) ExecuteTransaction(request CASRequest) (ok bool, err error)

func (*PrefixedAtomicStorage) Get

func (storage *PrefixedAtomicStorage) Get(key string) (value string, ok bool, err error)

Get is implementation of AtomicStorage.Get

func (*PrefixedAtomicStorage) GetByKeyPrefix

func (storage *PrefixedAtomicStorage) GetByKeyPrefix(prefix string) (values []string, err error)

func (*PrefixedAtomicStorage) Put

func (storage *PrefixedAtomicStorage) Put(key string, value string) (err error)

Put is implementation of AtomicStorage.Put

func (*PrefixedAtomicStorage) PutIfAbsent

func (storage *PrefixedAtomicStorage) PutIfAbsent(key string, value string) (ok bool, err error)

PutIfAbsent is implementation of AtomicStorage.PutIfAbsent

func (*PrefixedAtomicStorage) StartTransaction

func (storage *PrefixedAtomicStorage) StartTransaction(conditionKeys []string) (transaction Transaction, err error)

type Transaction

type Transaction interface {
	GetConditionValues() ([]KeyValueData, error)
}

type TypedAtomicStorage

type TypedAtomicStorage interface {
	// Get returns value by key
	Get(key any) (value any, ok bool, err error)
	// GetAll returns an array which contains all values from storage
	GetAll() (array any, err error)
	// Put puts value by key unconditionally
	Put(key any, value any) (err error)
	// PutIfAbsent puts value by key if and only if key is absent in storage
	PutIfAbsent(key any, value any) (ok bool, err error)
	// CompareAndSwap puts newValue by key if and only if previous value is equal
	// to prevValue
	CompareAndSwap(key any, prevValue any, newValue any) (ok bool, err error)
	// Delete removes value by key
	Delete(key any) (err error)
	ExecuteTransaction(request TypedCASRequest) (ok bool, err error)
}

TypedAtomicStorage is an atomic storage which automatically serializes/deserializes values and keys

func NewTypedAtomicStorageImpl

func NewTypedAtomicStorageImpl(storage AtomicStorage, keySerializer func(key any) (serialized string, err error),
	keyType reflect.Type, valueSerializer func(value any) (serialized string, err error),
	valueDeserializer func(serialized string, value any) (err error),
	valueType reflect.Type) TypedAtomicStorage

type TypedAtomicStorageImpl

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

TypedAtomicStorageImpl is an implementation of TypedAtomicStorage interface

func (*TypedAtomicStorageImpl) CompareAndSwap

func (storage *TypedAtomicStorageImpl) CompareAndSwap(key any, prevValue any, newValue any) (ok bool, err error)

CompareAndSwap implements TypedAtomicStorage.CompareAndSwap

func (*TypedAtomicStorageImpl) Delete

func (storage *TypedAtomicStorageImpl) Delete(key any) (err error)

func (*TypedAtomicStorageImpl) ExecuteTransaction

func (storage *TypedAtomicStorageImpl) ExecuteTransaction(request TypedCASRequest) (ok bool, err error)

func (*TypedAtomicStorageImpl) Get

func (storage *TypedAtomicStorageImpl) Get(key any) (value any, ok bool, err error)

Get implements TypedAtomicStorage.Get

func (*TypedAtomicStorageImpl) GetAll

func (storage *TypedAtomicStorageImpl) GetAll() (array any, err error)

func (*TypedAtomicStorageImpl) Put

func (storage *TypedAtomicStorageImpl) Put(key any, value any) (err error)

Put implementor TypedAtomicStorage.Put

func (*TypedAtomicStorageImpl) PutIfAbsent

func (storage *TypedAtomicStorageImpl) PutIfAbsent(key any, value any) (ok bool, err error)

PutIfAbsent implements TypedAtomicStorage.PutIfAbsent

type TypedCASRequest

type TypedCASRequest struct {
	RetryTillSuccessOrError bool
	Update                  TypedUpdateFunc
	ConditionKeys           []any //Typed Keys
}

type TypedKeyValueData

type TypedKeyValueData struct {
	Key     any
	Value   any
	Present bool
}

type TypedTransaction

type TypedTransaction interface {
	GetConditionValues() ([]TypedKeyValueData, error)
}

type TypedUpdateFunc

type TypedUpdateFunc func(conditionValues []TypedKeyValueData) (update []TypedKeyValueData, ok bool, err error)

Best to change this to KeyValueData , will do this in the next commit

type UpdateFunc

type UpdateFunc func(conditionValues []KeyValueData) (update []KeyValueData, ok bool, err error)

Best to change this to KeyValueData , will do this in the next commit

Jump to

Keyboard shortcuts

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