kv

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0, BSD-2-Clause Imports: 0 Imported by: 4

Documentation

Index

Constants

View Source
const EmptyPrefix = Key("")

Variables

This section is empty.

Functions

func MustGet added in v0.1.0

func MustGet(kvs KVStore, key Key) []byte

func MustHas added in v0.1.0

func MustHas(kvs KVStore, key Key) bool

func MustIterate added in v0.1.0

func MustIterate(kvs KVStore, prefix Key, f func(key Key, value []byte) bool)

func MustIterateKeys added in v0.1.0

func MustIterateKeys(kvs KVStore, prefix Key, f func(key Key) bool)

Types

type KVStore

type KVStore interface {
	KVStoreWriter
	KVStoreReader
}

KVStore represents a key-value store where both keys and values are arbitrary byte slices.

type KVStoreReader added in v0.1.0

type KVStoreReader interface {
	// Get returns the value, or nil if not found
	Get(key Key) ([]byte, error)
	Has(key Key) (bool, error)
	Iterate(prefix Key, f func(key Key, value []byte) bool) error
	IterateKeys(prefix Key, f func(key Key) bool) error

	// MustGet returns the value, or nil if not found
	MustGet(key Key) []byte
	MustHas(key Key) bool
	MustIterate(prefix Key, f func(key Key, value []byte) bool)
	MustIterateKeys(prefix Key, f func(key Key) bool)
}

type KVStoreWriter added in v0.1.0

type KVStoreWriter interface {
	Set(key Key, value []byte)
	Del(key Key)
}

type Key

type Key string

Since map cannot have []byte as key, to avoid unnecessary conversions between string and []byte, we use string as key data type, but it does not necessarily have to be a valid UTF-8 string.

func (Key) HasPrefix

func (k Key) HasPrefix(prefix Key) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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