pgkeyvalue

package
v0.3.73-rc-4635a41 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyValue

type KeyValue struct {
	Key   string
	Value []byte
}

type PGKeyValueStore

type PGKeyValueStore struct {
	Logger *logrus.Logger
	// contains filtered or unexported fields
}

PGKeyValueStore is a time-limited key-value store backed by postgres with a local LRU cache. The store is write-only, i.e., writing to an existing key will return an error (of type *armadaerrors.ErrAlreadyExists). Keys can only be deleted by running the cleanup function. Deleting keys does not cause caches to update, i.e., nodes may have an inconsistent view if keys are deleted.

func New

func New(db *pgxpool.Pool, cacheSize int, tableName string) (*PGKeyValueStore, error)

func (*PGKeyValueStore) Add

func (c *PGKeyValueStore) Add(ctx context.Context, key string, value []byte) (bool, error)

Add adds a key-value pair. Returns true if successful and false if the key already exists. The postgres table backing the key-value storage is created automatically if it doesn't already exist.

func (*PGKeyValueStore) AddKey

func (c *PGKeyValueStore) AddKey(ctx context.Context, key string) (bool, error)

AddKey is equivalent to Add(ctx, key, nil).

func (*PGKeyValueStore) Cleanup

func (c *PGKeyValueStore) Cleanup(ctx context.Context, lifespan time.Duration) error

Cleanup removes all key-value pairs older than lifespan.

func (*PGKeyValueStore) Get

func (c *PGKeyValueStore) Get(ctx context.Context, key string) ([]byte, error)

Get returns the value associated with the provided key, or &armadaerrors.ErrNotFound if the key can't be found.

func (*PGKeyValueStore) LoadOrStoreBatch

func (c *PGKeyValueStore) LoadOrStoreBatch(ctx context.Context, batch []*KeyValue) (map[string][]byte, error)

LoadOrStoreBatch returns the existing values for the supplied keys if present. Otherwise, it stores and returns the supplied value. The postgres table backing the key-value storage is created automatically if it doesn't already exist.

func (*PGKeyValueStore) PeriodicCleanup

func (c *PGKeyValueStore) PeriodicCleanup(ctx context.Context, interval time.Duration, lifespan time.Duration) error

PeriodicCleanup starts a goroutine that automatically runs the cleanup job every interval until the provided context is cancelled.

Jump to

Keyboard shortcuts

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