kvmemdb

package
v0.0.0-...-c2b9891 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 15 Imported by: 2

Documentation

Overview

Package kvmemdb implements an in-memory key-value database with snapshots and read/write transactions. Snapshots can be taken periodically to backup and restore the database.

Database can be used by multiple goroutines simultaneously, however, individual Snapshot and Transaction objects are not thread-safe; they can only be used by a single goroutine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backup

func Backup(db *DB, file string) error

Backup saves database content to a file.

func Compact

func Compact(ctx context.Context, db *DB) int

Compact removes unnecessary values from the database. Returns number of keys compacted.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func New

func New() *DB

func Restore

func Restore(file string) (*DB, error)

Restore loads database from a file.

func (*DB) NewSnapshot

func (db *DB) NewSnapshot(ctx context.Context) (kv.Snapshot, error)

func (*DB) NewTransaction

func (db *DB) NewTransaction(ctx context.Context) (kv.Transaction, error)

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

func (*Iterator) Fetch

func (it *Iterator) Fetch(ctx context.Context, advance bool) (string, io.Reader, error)

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

func (*Snapshot) Ascend

func (s *Snapshot) Ascend(ctx context.Context, begin, end string) (kv.Iterator, error)

func (*Snapshot) Descend

func (s *Snapshot) Descend(ctx context.Context, begin, end string) (kv.Iterator, error)

func (*Snapshot) Discard

func (s *Snapshot) Discard(ctx context.Context) error

func (*Snapshot) Get

func (s *Snapshot) Get(ctx context.Context, key string) (io.Reader, error)

func (*Snapshot) Scan

func (s *Snapshot) Scan(ctx context.Context) (kv.Iterator, error)

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

func (*Transaction) Ascend

func (t *Transaction) Ascend(ctx context.Context, begin, end string) (kv.Iterator, error)

func (*Transaction) Commit

func (t *Transaction) Commit(ctx context.Context) error

func (*Transaction) Delete

func (t *Transaction) Delete(ctx context.Context, key string) error

func (*Transaction) Descend

func (t *Transaction) Descend(ctx context.Context, begin, end string) (kv.Iterator, error)

func (*Transaction) Get

func (t *Transaction) Get(ctx context.Context, key string) (io.Reader, error)

func (*Transaction) Rollback

func (t *Transaction) Rollback(ctx context.Context) error

func (*Transaction) Scan

func (t *Transaction) Scan(ctx context.Context) (kv.Iterator, error)

func (*Transaction) Set

func (t *Transaction) Set(ctx context.Context, key string, value io.Reader) error

func (*Transaction) String

func (t *Transaction) String() string

Jump to

Keyboard shortcuts

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