kvndb

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2021 License: MIT Imports: 16 Imported by: 0

README

Go Reference GitHub Workflow Status (branch)

kvnDB - Key-Value Non-DataBase

kvnDB (pronounced as "Kevin Dee Bee") is not a database. It is a lame embedded in-memory key-value storage with on-demand snapshots and some sort of history keeping.

Features

  • Fast operations. All data is stored in memory. Watch out for OOM
  • Thread/goroutine safe. All operations are done via mutex, so reading and writing data can be done from different routines (but watch out for concurrency)
  • Simple API. Very simple
  • On-demand persistence. Via API data snapshot can be written to disk. Watch for disk space/IO as data written uncompressed
  • Snapshot history. Can maintain desired history of snapshots. See API for Save()

Why

  • When need simple and fast data storage
  • When need that storage also be persisted to disk

Usage

Get it:

$ go get github.com/akamensky/kvndb

See documentation for API

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound      = errors.New("kvndb: key not found")
	ErrTooMuchHistory   = errors.New("kvndb: do you really need that much history")
	ErrSnapshotNotFound = errors.New("kvndb: there are no loadable snapshots, data was reset")
	ErrAlreadyClosed    = errors.New("kvndb: operations on closed datastore are not possible")
	ErrBadSnapshot      = errors.New("kvndb: checksum mismatch likely snapshot corrupted")
)

Functions

This section is empty.

Types

type DB

type DB interface {
	// Put adds or updates entry for given key.
	Put(key, value []byte) error

	// Get returns value for given key, ErrKeyNotFound if key
	// does not exist.
	Get(key []byte) ([]byte, error)

	// Delete removes entry for given key.
	Delete(key []byte) error

	// Size returns the number of currently stored entries.
	Size() uint64

	// Keys returns a channel that will iterate	over keys of all
	// entries.This operation is synchronous, which means all
	// other operations will be	blocked until all values are read.
	// You MUST read all values until the channel is closed. Best
	// to use `range`.
	Keys() (<-chan []byte, error)

	// KeysAndValues returns a channel that will iterate
	// over all keys and values of all entries. This operation
	// is synchronous, which means all other operations will be
	// blocked until all values are read. You MUST read all values
	// until the channel is closed. Best to use `range`.
	KeysAndValues() (<-chan *Tuple, error)

	// Save will write a snapshot of data into provided
	// directory path. If snapshot successful it will clean up
	// keeping only `hist` number of snapshots. This operation
	// is synchronous, which means all other operations will be
	// blocked until it is done. `hist` value of 0 will only
	// save current copy. Value of 1 will keep current and previous.
	Save(dir string, hist uint) error

	// Load will load data from snapshot. It will replace any
	// current data completely (not merge/update). It will
	// always load latest found snapshot version. This operation
	// is synchronous, which means all other operations will be
	// blocked until it is done.
	Load(dir string) error

	// Wait will block until a previously started operation frees
	// mutex. If datastore was already closed, it is a no-op.
	Wait()

	// Close reset the data store and set status to closed. After
	// this no operations can be done.
	Close() error
}

func New

func New() DB

type Tuple

type Tuple struct {
	Key   []byte
	Value []byte
}

Jump to

Keyboard shortcuts

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