disk

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2020 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	Incr(k string, by int64) (int64, error)
	Set(k string, v []byte, ttl time.Duration) error
	MSet(data map[string][]byte) error
	Get(k string) ([]byte, error)
	MGet(keys []string) [][]byte
	TTL(key string) int64
	MDel(keys []string) error
	Del(key string) error
	Scan(ScannerOpt ScannerOptions) error
	Size() int64
	GC() error
	Close()
}

DB Interface

type LevelDB

type LevelDB struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LevelDB - represents a leveldb db implementation

func OpenLevelDB

func OpenLevelDB(path string) (*LevelDB, error)

OpenLevelDB - Opens the specified path

func (*LevelDB) Close

func (ldb *LevelDB) Close()

Close ...

func (*LevelDB) Del

func (ldb *LevelDB) Del(key string) error

Del - removes key from the store

func (*LevelDB) GC

func (ldb *LevelDB) GC() error

GC - runs the garbage collector

func (*LevelDB) Get

func (ldb *LevelDB) Get(k string) ([]byte, error)

Get - fetches the value of the specified k

func (*LevelDB) Incr

func (ldb *LevelDB) Incr(k string, by int64) (int64, error)

Incr - increment the key by the specified value

func (*LevelDB) MDel

func (ldb *LevelDB) MDel(keys []string) error

MDel - removes key(s) from the store

func (*LevelDB) MGet

func (ldb *LevelDB) MGet(keys []string) [][]byte

MGet - fetch multiple values of the specified keys

func (*LevelDB) MSet

func (ldb *LevelDB) MSet(data map[string][]byte) error

MSet - sets multiple key-value pairs

func (*LevelDB) Scan

func (ldb *LevelDB) Scan(scannerOpt ScannerOptions) error

Scan - iterate over the whole store using the handler function

func (*LevelDB) Set

func (ldb *LevelDB) Set(k string, v []byte, ttl time.Duration) error

Set - sets a key with the specified value and optional ttl

func (*LevelDB) Size

func (ldb *LevelDB) Size() int64

Size - returns the size of the database in bytes

func (*LevelDB) TTL

func (ldb *LevelDB) TTL(key string) int64

TTL - returns the time to live of the specified key's value

type ScannerOptions

type ScannerOptions struct {
	// from where to start
	Offset string

	// whether to include the value of the offset in the result or not
	IncludeOffset bool

	// the prefix that must be exists in each key in the iteration
	Prefix string

	// fetch the values (true) or this is a key only iteration (false)
	FetchValues bool

	// the handler that handles the incoming data
	Handler func(k []byte, v []byte) error
}

ScannerOptions - represents the options for a scanner

Jump to

Keyboard shortcuts

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