db

package
v0.0.0-...-550e0f3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerDB

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

func (*BadgerDB) Close

func (bdb *BadgerDB) Close() error

Close implements the DB interface. Closes the DB connection and invokes ctx cancel.

func (*BadgerDB) Del

func (bdb *BadgerDB) Del(key []byte) error

Del implements the DB interface, deletes key or error.

func (*BadgerDB) GenID

func (bdb *BadgerDB) GenID() (id []byte, err error)

GenID implements the DB interface. It generates a random id, retrying until it generates one which does not already exist in the DB or returns error.

func (*BadgerDB) Get

func (bdb *BadgerDB) Get(key []byte) (item Item, err error)

Get implements the DB interface, returns key if exists or error.

func (*BadgerDB) GetAll

func (bdb *BadgerDB) GetAll() (items map[string]Item, err error)

GetAll implements the DB interface, returns all keys and values or error.

func (*BadgerDB) GetExpiration

func (bdb *BadgerDB) GetExpiration(items map[string]Item) (itemss map[string]ItemS)

GetExpiration implements the DB interface, for a given map of Items it will convert Item.Expiry from a time.Duration to a string and return a new collection of ItemS (map[string]ItemS) or error.

func (*BadgerDB) Has

func (bdb *BadgerDB) Has(key []byte) (exists bool, err error)

Has implements the DB interface, returns bool if key is present or not, Error only returned if not badger.ErrKeyNotFound.

func (*BadgerDB) KeyCount

func (bdb *BadgerDB) KeyCount() int

KeyCount implements the DB interface, returns count of total keys or error.

func (*BadgerDB) Set

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

Set implements the DB interface, stores value at key or error.

type DB

type DB interface {
	Get(key []byte) (item Item, err error)
	Set(key, value []byte, ttl time.Duration) error
	Del(key []byte) error
	Has(key []byte) (bool, error)
	KeyCount() int
	GetAll() (items map[string]Item, err error)
	GenID() (id []byte, err error)
	GetExpiration(items map[string]Item) (itemss map[string]ItemS)
	Close() error
}
var KV DB

func NewBadgerDB

func NewBadgerDB(dataDir string, encryptionKey []byte, logger *zap.SugaredLogger) (DB, error)

NewBadgerDB returns a new, initialized BadgerDB database implementing DB.

type Item

type Item struct {
	Value   string
	Expires time.Duration
}

type ItemS

type ItemS struct {
	Value   string
	Expires string
}

type ItemST

type ItemST struct {
	Value      string
	Expires    string
	Expiration string
}

Jump to

Keyboard shortcuts

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