kv

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package kv provides an abstraction of a non-transactional key/value store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTests

func RunTests(
	t *testing.T,
	newStore func(t *testing.T) Store,
)

RunTests runs tests that confirm a journal implementation behaves correctly.

Types

type Keyspace

type Keyspace interface {
	// Get returns the value associated with k.
	//
	// If the key does not exist v is empty.
	Get(ctx context.Context, k []byte) (v []byte, err error)

	// Has returns true if k is present in the keyspace.
	Has(ctx context.Context, k []byte) (ok bool, err error)

	// Set associates a value with k.
	//
	// If v is empty, the key is deleted.
	Set(ctx context.Context, k, v []byte) error

	// Range invokes fn for each key in the keyspace in an undefined order.
	Range(ctx context.Context, fn RangeFunc) error

	// Close closes the keyspace.
	Close() error
}

A Keyspace is an isolated collection of key/value pairs.

type RangeFunc

type RangeFunc func(ctx context.Context, k, v []byte) (ok bool, err error)

A RangeFunc is a function used to range over the key/value pairs in a Keyspace.

If err is non-nil, ranging stops and err is propagated up the stack. Otherwise, if ok is false, ranging stops without any error being propagated.

type Store

type Store interface {
	// Open returns the keyspace with the given name.
	Open(ctx context.Context, name string) (Keyspace, error)
}

Store is a collection of keyspaces.

Jump to

Keyboard shortcuts

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