kv

package
v0.0.0-...-36bb858 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExistsUsingList

func ExistsUsingList[K any](ctx context.Context, s Lister[K], k K) (bool, error)

ExistsUsingList implements Exists in terms of List

func ForEach

func ForEach[K any](ctx context.Context, x Lister[K], span state.Span[K], fn func(K) error) error

ForEach calls fn with all the keys in x constrained by gteq, and lt if they exist. `fn` may be called in another go rountine during the execution of ForEachSpan. `fn` will not be called after ForEachSpan returns.

func Get

func Get[K, V any](ctx context.Context, x Getter[K, V], k K) (ret V, _ error)

Get is a convenience function for retrieving a value without declaring a destination variable.

Types

type Deleter

type Deleter[K any] interface {
	// Delete removes the data at k
	Delete(ctx context.Context, k K) error
}

Deleter has the Delete method

type Entry

type Entry[K, V any] struct {
	Key   K
	Value V
}

Entry is a key value mapping.

type Exister

type Exister[K any] interface {
	// Exists returns true if the store contains an entry for k and false otherwise.
	Exists(ctx context.Context, k K) (bool, error)
}

Exister has the Exists method

type Getter

type Getter[K, V any] interface {
	Get(ctx context.Context, k K, dst *V) error
}

Getter has the Get method

type Lister

type Lister[K any] interface {
	// List copies keys from the store into the slice entries
	// and returns the number copied.
	// List signals the end of the list by returning (0, nil)
	// List may fill ks with fewer than len(ks), but will always return > 0, unless it is the end.
	// List will only return keys which are contained by in the span.
	List(ctx context.Context, span state.Span[K], ks []K) (int, error)
}

Lister has the List method.

type MemStore

type MemStore[K, V any] struct {
	// contains filtered or unexported fields
}

func NewMemStore

func NewMemStore[K, V any](cmp func(a, b K) int) *MemStore[K, V]

func (*MemStore[K, V]) Delete

func (s *MemStore[K, V]) Delete(ctx context.Context, k K) error

func (*MemStore[K, V]) Exists

func (s *MemStore[K, V]) Exists(ctx context.Context, k K) (bool, error)

func (*MemStore[K, V]) Get

func (s *MemStore[K, V]) Get(ctx context.Context, k K, dst *V) error

func (*MemStore[K, V]) Len

func (s *MemStore[K, V]) Len() (count int)

func (*MemStore[K, V]) List

func (s *MemStore[K, V]) List(ctx context.Context, span state.Span[K], buf []K) (n int, err error)

func (*MemStore[K, V]) Modify

func (s *MemStore[K, V]) Modify(ctx context.Context, fn func(Store[K, V]) error) error

func (*MemStore[K, V]) Put

func (s *MemStore[K, V]) Put(ctx context.Context, k K, v V) error

func (*MemStore[K, V]) View

func (s *MemStore[K, V]) View(ctx context.Context, fn func(ReadOnlyStore[K, V]) error) error

type Poster

type Poster[K, V any] interface {
	// Post creates an entry holding v and returns a key for it.
	Post(ctx context.Context, v V) (K, error)
}

Poster has the Post method

type Putter

type Putter[K, V any] interface {
	// Put replaces data at key with value, or creates a mapping from k -> v
	// if it does not exist.
	Put(ctx context.Context, k K, v V) error
}

Putter has the Put method

type ReadOnlyStore

type ReadOnlyStore[K, V any] interface {
	Getter[K, V]
	Lister[K]
}

ReadOnlyStore is a KVStore which does not allow mutating data.

type Store

type Store[K, V any] interface {
	Getter[K, V]
	Putter[K, V]
	Deleter[K]
	Lister[K]
	Exister[K]
}

Store is an ordered Key-Value Store

type StoreTx

type StoreTx[K, V any] interface {
	// View calls fn with a ReadOnly view of the store
	View(ctx context.Context, fn func(tx ReadOnlyStore[K, V]) error) error
	// Modify calls fn with a mutable view of the store.
	// Any operations on the store are either all applied if fn and Modify both return nil,
	// or all reverted if either fn or View returns a non-nil error.
	Modify(ctx context.Context, fn func(tx Store[K, V]) error) error
}

StoreTx is a transactional key value store

type Updater

type Updater[K, V any] interface {
	// Update applies an update to a key serially with other calls to update
	Update(ctx context.Context, k K, fn func(v *V) (*V, error)) error
}

Updater has the Update method

Jump to

Keyboard shortcuts

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