store

package
v0.0.0-...-8568aec Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2017 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltStore

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

BoltStore implements the KVStore with boltDB as backend; it uses a single bucket to simplify interaction with DB.

func NewBoltStore

func NewBoltStore(path string) (*BoltStore, error)

NewBoltStore returns a NewBoltStore instance; it will open the BoltDB and create the bucket if needed. It is by design that only one bucket is used per DB and its name is fixed.

func (*BoltStore) Get

func (s *BoltStore) Get(key []byte) (value []byte, err error)

Get copies the returning []byte from db.View() to make sure it keeps valid outside the transaction. Refer to https://github.com/boltdb/bolt#using-keyvalue-pairs.

func (*BoltStore) Peek

func (s *BoltStore) Peek(key []byte, f PeekFunc) error

Peek allows access to the value at given key through the PeekFunc; note that values from BoltDB's View are only transaction-valid.

func (*BoltStore) Set

func (s *BoltStore) Set(key, value []byte) error

Set stores key-value pair in a boltDB update-transaction.

type KVStore

type KVStore interface {
	// Get retrieves the value by certain key,
	// and returns nil if key is not existed.
	Get(key []byte) (value []byte, err error)

	// Set stores the key-value pair with
	// the update-if-existed fashion.
	Set(key, value []byte) error
}

KVStore is a simple key-value database.

type PeekFunc

type PeekFunc func([]byte) error

PeekFunc provides the callback-style access to the value.

Jump to

Keyboard shortcuts

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