kv

package
v0.0.0-...-11acf48 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2018 License: BSD-3-Clause Imports: 0 Imported by: 4

Documentation

Overview

Package kv contains a generic interface for key-value databases with support for batch writes. All operations are safe for concurrent use, atomic and synchronously persistent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IncrementKey

func IncrementKey(prefix []byte) []byte

IncrementKey returns the lexicographically first DB key which is greater than all keys prefixed by "prefix". Following the Range.Limit convention, IncrementKey may return nil, a sentinel value that is to be interpreted as greater than all keys.

Types

type Batch

type Batch interface {
	Reset()
	Put(key, value []byte)
	Delete(key []byte)
}

A Batch contains a sequence of Put-s waiting to be Write-n to a DB.

type DB

type DB interface {
	Get(key []byte) ([]byte, error)
	Put(key, value []byte) error
	Delete(key []byte) error
	NewBatch() Batch
	Write(Batch) error
	NewIterator(*Range) Iterator
	Close() error

	ErrNotFound() error
}

DB is an abstract ordered key-value store. All operations are assumed to be synchronous, atomic and linearizable. This includes the following guarantee: After Put(k, v) has returned, and as long as no other Put(k, ?) has been called happened, Get(k) MUST return always v, regardless of whether the process or the entire system has been reset in the meantime or very little time has passed. To amortize the overhead of synchronous writes, DB offers batch operations: Write(...) performs a series of Put-s atomically (and possibly almost as fast as a single Put).

type Iterator

type Iterator interface {
	Key() []byte
	Value() []byte
	First() bool
	Next() bool
	Last() bool
	Release()
	Error() error
}

Iterator is an abstract pointer to a DB entry. It must be valid to call Error() after release. The boolean return values indicate whether the requested entry exists.

type Range

type Range struct {
	// Start of the key range, included in the range.
	Start []byte

	// Limit of the key range, not included in the range. nil indicates no limit.
	Limit []byte
}

Range is a key range.

func BytesPrefix

func BytesPrefix(prefix []byte) *Range

BytesPrefix returns key range that satisfy the given prefix.

Directories

Path Synopsis
Package leveldbkv implements the kv interface using leveldb.
Package leveldbkv implements the kv interface using leveldb.

Jump to

Keyboard shortcuts

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