gkvdb

package
v2.0.0-...-cbac34e Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gkvdb provides a lightweight, embeddable and persistent key-value database.

Index

Constants

View Source
const (
	// Default instance name.
	DEFAULT_NAME = "default"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

func Instance

func Instance(name ...string) *DB

Instance returns an instance of DB with specified name. The <name> param is unnecessary, if <name> is not passed, it returns a instance with default name.

func New

func New(options ...Options) *DB

New creates and returns a new db object.

func (*DB) Begin

func (db *DB) Begin(update bool) *TX

Begin starts the transaction for db.

func (*DB) Close

func (db *DB) Close() error

Close closes the db.

func (*DB) Delete

func (db *DB) Delete(key []byte) error

Delete removed data specified by <key> from current db.

func (*DB) Get

func (db *DB) Get(key []byte) (value []byte)

Get returns the value with given key. It returns nil if <key> is not found in the db.

func (*DB) Iterate

func (db *DB) Iterate(prefix []byte, f func(key, value []byte) bool)

Iterate is alias of IterateAsc. See IterateAsc.

func (*DB) IterateAsc

func (db *DB) IterateAsc(prefix []byte, f func(key, value []byte) bool)

IteratorAsc iterates the db in ascending order with given callback function <f> starting from <seek>. If <seek> is nil it iterates from the beginning of the db. If <f> returns true, then it continues iterating; or false to stop.

func (*DB) IterateDesc

func (db *DB) IterateDesc(prefix []byte, f func(key, value []byte) bool)

IteratorDesc iterates the db in descending order with given callback function <f> starting from <seek>. If <prefix> is nil it iterates from the beginning of the db. If <f> returns true, then it continues iterating; or false to stop.

func (*DB) Options

func (db *DB) Options() *Options

Options return the options of current db object.

func (*DB) Set

func (db *DB) Set(key []byte, value []byte, ttl ...time.Duration) (err error)

Set sets <key>-<value> pair data to current db with <ttl>. The <ttl> is optional, which is not expired in default.

func (*DB) SetOptions

func (db *DB) SetOptions(options Options) error

SetOptions sets the options for db.

func (*DB) SetPath

func (db *DB) SetPath(path string) error

SetPath sets the storage folder path for db.

func (*DB) Size

func (db *DB) Size() int64

Size returns the data count of current db.

type Options

type Options = badger.Options

func DefaultOptions

func DefaultOptions(path string) Options

DefaultOptions returns the default options for gkvdb.

type TX

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

TX is the transaction object for db.

func (*TX) Commit

func (tx *TX) Commit() error

Commit commits the changes and close the transaction.

func (*TX) Delete

func (tx *TX) Delete(key []byte) error

Delete removed data specified by <key> from current db in this transaction.

func (*TX) Get

func (tx *TX) Get(key []byte) (value []byte)

Get returns the value with given key in this transaction. It returns nil if <key> is not found in the db.

func (*TX) Iterate

func (tx *TX) Iterate(prefix []byte, f func(key, value []byte) bool)

Iterate is alias of IterateAsc. See IterateAsc.

func (*TX) IterateAsc

func (tx *TX) IterateAsc(prefix []byte, f func(key, value []byte) bool)

IteratorAsc iterates the db in ascending order with given callback function <f> starting from <prefix>. If <seek> is nil it iterates from the beginning of the db. If <f> returns true, then it continues iterating; or false to stop.

func (*TX) IterateDesc

func (tx *TX) IterateDesc(prefix []byte, f func(key, value []byte) bool)

IteratorDesc iterates the db in descending order with given callback function <f> starting from <prefix>. If <seek> is nil it iterates from the beginning of the db. If <f> returns true, then it continues iterating; or false to stop.

func (*TX) Rollback

func (tx *TX) Rollback()

Rollback discards the changes and close the transaction.

func (*TX) Set

func (tx *TX) Set(key []byte, value []byte, ttl ...time.Duration) error

Set sets <key>-<value> pair data to current db with <ttl> in this transaction. The <ttl> is optional, which is not expired in default.

Jump to

Keyboard shortcuts

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