store

package
v0.0.0-...-7101970 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsKeyNotFound

func IsKeyNotFound(err error) bool

Types

type Engine

type Engine interface {
	// Name engine name
	Name() string

	// Txn read-write transaction
	Txn(fn func(KVTxn) error) error

	// View read-only transaction
	View(fn func(KVTxn) error) error

	// Update read-write transaction
	Update(fn func(KVTxn) error) error

	// Snapshot return a mvcc snapshot
	Snapshot() (Snapshot, error)

	// Close engine
	Close() error
}

Engine support txn

func NewEngine

func NewEngine(dir string) (Engine, error)

NewEngine creates a new txn engine

type KVTxn

type KVTxn interface {
	Get(key []byte) ([]byte, error)
	Gets(keys ...[]byte) ([][]byte, error)
	Set(key, value []byte) error
	Delete(key []byte) error
	Deletes(keys ...[]byte) error
	Incr(key []byte, value uint64) (uint64, error)
	Append(key, value []byte) ([]byte, error)
	Exist(key []byte) (bool, error)
	Add(key, value []byte) error
	Merge(key []byte, fn MergeFunc) ([]byte, error)
	ScanRange(begin, end []byte) (map[string][]byte, error)
	ScanKeys(prefix []byte, limit int) ([][]byte, error)
	ScanValues(prefix []byte, limit int) (map[string][]byte, error)
}

KVTxn for store

type MergeFunc

type MergeFunc func(existingVal, newVal []byte) []byte

MergeFunc accepts two byte slices, one representing an existing value, and another representing a new value that needs to be ‘merged’ into it. MergeFunc contains the logic to perform the ‘merge’ and return an updated value. MergeFunc could perform operations like integer addition, list appends etc. Note that the ordering of the operands is maintained.

type Snapshot

type Snapshot interface {
	Name() string
	Get(key []byte) ([]byte, error)
	ScanRange(begin, end []byte) (map[string][]byte, error)
	ScanKeys(prefix []byte, limit int) ([][]byte, error)
	Close() error
}

Snapshot mvcc snapshot

Jump to

Keyboard shortcuts

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