memory

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryConnection

type MemoryConnection struct {
	Address string
	Port    int
	// contains filtered or unexported fields
}

func NewMemoryConnection

func NewMemoryConnection(address string, port int) *MemoryConnection

func (*MemoryConnection) Connect

func (m *MemoryConnection) Connect() error

func (*MemoryConnection) Delete

func (m *MemoryConnection) Delete(key string) error

func (*MemoryConnection) Get

func (m *MemoryConnection) Get(key string, value any) error

func (*MemoryConnection) Put

func (m *MemoryConnection) Put(key string, value any) error

type MemoryConnectionInterface

type MemoryConnectionInterface interface {
	// Connect establishes a connection to the memory database.
	Connect() error

	// Get retrieves the value associated with the given key from the memory database.
	// The value is stored in the 'value' parameter.
	Get(key string, value any) error

	// Put stores the given value in the memory database with the specified key.
	Put(key string, value any) error

	// Delete removes the value associated with the given key from the memory database.
	Delete(key string) error
}

MemoryConnectionInterface represents an interface for a memory connection.

type MemoryDatabase

type MemoryDatabase struct {
	Address string
	Port    int

	MsgChan chan string
	// contains filtered or unexported fields
}

func NewMemoryDatabase

func NewMemoryDatabase(address string, port int) *MemoryDatabase

func (*MemoryDatabase) Start

func (m *MemoryDatabase) Start() error

func (*MemoryDatabase) Stop

func (m *MemoryDatabase) Stop()

type MemoryDatastore

type MemoryDatastore struct {
	Name string
	Txn  *txn.Transaction
	// contains filtered or unexported fields
}

func NewMemoryDatastore

func NewMemoryDatastore(name string, conn MemoryConnectionInterface) *MemoryDatastore

func (*MemoryDatastore) Abort

func (m *MemoryDatastore) Abort(hasCommitted bool) error

Abort discards the changes made in the current transaction. If hasCommitted is false, it clears the write cache. If hasCommitted is true, it rolls back the changes made by the current transaction. It returns an error if there is any issue during the rollback process.

func (*MemoryDatastore) Commit

func (m *MemoryDatastore) Commit() error

Commit updates the state of records in the data store to COMMITTED. It iterates over the write cache and updates each record's state to COMMITTED. After updating the records, it clears the write cache. Returns an error if there is any issue updating the records or clearing the cache.

func (*MemoryDatastore) Copy

func (m *MemoryDatastore) Copy() txn.Datastorer

Copy returns a new instance of MemoryDatastore that is a copy of the current datastore. The copy shares the same name and connection as the original datastore.

func (*MemoryDatastore) Delete

func (m *MemoryDatastore) Delete(key string) error

func (*MemoryDatastore) DeleteTSR

func (m *MemoryDatastore) DeleteTSR(txnId string) error

DeleteTSR deletes a transaction with the given transaction ID from the memory datastore. It returns an error if the deletion operation fails.

func (*MemoryDatastore) GetName

func (m *MemoryDatastore) GetName() string

GetName returns the name of the MemoryDatastore.

func (*MemoryDatastore) Prepare

func (m *MemoryDatastore) Prepare() error

func (*MemoryDatastore) Prev

func (m *MemoryDatastore) Prev(key string, record string)

func (*MemoryDatastore) Read

func (m *MemoryDatastore) Read(key string, value any) error

func (*MemoryDatastore) ReadTSR

func (m *MemoryDatastore) ReadTSR(txnId string) (config.State, error)

func (*MemoryDatastore) Recover

func (m *MemoryDatastore) Recover(key string)

func (*MemoryDatastore) SetTxn

func (m *MemoryDatastore) SetTxn(txn *txn.Transaction)

SetTxn sets the transaction for the MemoryDatastore. It takes a pointer to a Transaction as input and assigns it to the Txn field of the MemoryDatastore.

func (*MemoryDatastore) Start

func (m *MemoryDatastore) Start() error

func (*MemoryDatastore) Write

func (m *MemoryDatastore) Write(key string, value any) error

func (*MemoryDatastore) WriteTSR

func (m *MemoryDatastore) WriteTSR(txnId string, txnState config.State) error

WriteTSR writes the transaction state (txnState) associated with the given transaction ID (txnId) to the memory datastore. It returns an error if the write operation fails.

type MockMemoryConnection

type MockMemoryConnection struct {
	*MemoryConnection
	// contains filtered or unexported fields
}

MockMemoryConnection is a mock of MemoryConnection When Put is called, it will return error when debugCounter is 0 Semantically, it means `Put()` call will succeed X times

func NewMockMemoryConnection

func NewMockMemoryConnection(address string, port int, limit int,
	isReturned bool, debugFunc func() error) *MockMemoryConnection

func (*MockMemoryConnection) Put

func (m *MockMemoryConnection) Put(key string, value any) error

Jump to

Keyboard shortcuts

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