keyvaluestore

package
v0.0.0-...-ab25c98 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartGRPCServer

func StartGRPCServer(enableLogging bool, enableSecurity bool) error

StartGRPCServer starts a gRPC server on port 50051. If enableLogging is true, it initializes logging to the specified file with a rotation interval of 1 hour.

Types

type GRPCServer

type GRPCServer struct {
	proto.UnimplementedKeyValueServiceServer
	// contains filtered or unexported fields
}

func NewGRPCServer

func NewGRPCServer() *GRPCServer

NewGRPCServer creates a new gRPC server with an empty key-value store.

func (*GRPCServer) Delete

Delete deletes an item in the key-value store by key.

func (*GRPCServer) DeleteAll

DeleteAll deletes all items in the key-value store.

func (*GRPCServer) Get

Get returns an item in the key-value store by key.

func (*GRPCServer) GetAll

GetAll returns all items in the key-value store.

func (*GRPCServer) GetKeys

GetKeys returns all keys in the key-value store.

func (*GRPCServer) GetValues

GetValues returns all values in the key-value store.

func (*GRPCServer) Set

Set sets an item in the key-value store by key and value.

type KeyValue

type KeyValue struct {
	Key   string          `json:"key"`
	Value json.RawMessage `json:"value"`
}

func NewKeyValue

func NewKeyValue(key string, value json.RawMessage) *KeyValue

type KeyValueStore

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

KeyValueStore represents the key-value store.

func NewKeyValueStore

func NewKeyValueStore() *KeyValueStore

NewKeyValueStore creates a new instance of KeyValueStore.

func (*KeyValueStore) Delete

func (kv *KeyValueStore) Delete(key string) ([]byte, bool)

Deletes a specific key value pair from the store.

func (*KeyValueStore) DeleteALL

func (kv *KeyValueStore) DeleteALL() error

Deletes all key/value pairs from the store and clears the transaction logs.

func (*KeyValueStore) Get

func (kv *KeyValueStore) Get(key string) (json.RawMessage, bool)

Get retrieves the value associated with a key from the store.

func (*KeyValueStore) GetAll

func (kv *KeyValueStore) GetAll() map[string][]byte

GetAll retries all key-values pairs from the store.

func (*KeyValueStore) GetKeys

func (kv *KeyValueStore) GetKeys() []string

GetKeys returns all keys from the store.

func (*KeyValueStore) GetValues

func (kv *KeyValueStore) GetValues() []json.RawMessage

GetValues returns all values from the store.

func (*KeyValueStore) InitLogging

func (kv *KeyValueStore) InitLogging(logFile string, snapshotInterval time.Duration) error

func (*KeyValueStore) LoadLatestSnapshot

func (kv *KeyValueStore) LoadLatestSnapshot() error

func (*KeyValueStore) ProcessLogEntries

func (kv *KeyValueStore) ProcessLogEntries(entries []LogEntry)

ProcessLogEntries processes a list of log entries and updates the key-value store accordingly.

func (*KeyValueStore) Set

func (kv *KeyValueStore) Set(key string, value json.RawMessage)

Set adds or updates a key-value pair in the store.

func (*KeyValueStore) TakeSnapshot

func (kv *KeyValueStore) TakeSnapshot() error

type LogEntry

type LogEntry struct {
	Timestamp time.Time `json:"timestamp"`
	Operation string    `json:"operation"`
	Key       string    `json:"key"`
	Value     string    `json:"value"`
}

LogEntry represents a log entry.

type Logger

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

Logger is a simple logger that writes to a file.

func NewLogger

func NewLogger(filename string) (*Logger, error)

NewLogger creates a new logger that writes to the specified file.

func (*Logger) ClearLogs

func (l *Logger) ClearLogs() error

ClearLogs clears the entire transaction log file.

func (*Logger) ReadLogs

func (l *Logger) ReadLogs() ([]LogEntry, error)

ReadLogs reads all log entries from the file.

func (*Logger) WriteLog

func (l *Logger) WriteLog(entry LogEntry)

WriteLog writes a log entry to the logger's file.

type Snapshot

type Snapshot struct {
	Data      map[string]json.RawMessage `json:"data"`
	Timestamp time.Time                  `json:"timestamp"`
}

Jump to

Keyboard shortcuts

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