store

package
v0.0.0-...-23397e3 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 6 Imported by: 0

README

Key-value Store

This package provides a wrapper for a simple key-value store. The underlying database may be changed later.

Tested key-value packages:

  • Pebble: Has many dependencies and increases the binary file size by ~6 MB.
  • Pogreb: Currently used. Limited to 4 billion records due to 32-bit uint used as index.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryStore

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

MemoryStore is a simple in-memory key-value store for testing purposes.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore create a properly initialized memory store.

func (*MemoryStore) Count

func (ms *MemoryStore) Count() uint64

Count returns the count of records stored.

func (*MemoryStore) Delete

func (ms *MemoryStore) Delete(key []byte)

Delete deletes a key-value pair.

func (*MemoryStore) ExpireKeys

func (ms *MemoryStore) ExpireKeys()

ExpireKeys is called to delete all keys that are marked for expiration.

func (*MemoryStore) Get

func (ms *MemoryStore) Get(key []byte) (data []byte, found bool)

Get returns the value for the key if present.

func (*MemoryStore) Iterate

func (ms *MemoryStore) Iterate(callback func(key, value []byte))

Iterate iterates over all records.

func (*MemoryStore) Set

func (ms *MemoryStore) Set(key []byte, data []byte) error

Set stores the key-value pair.

func (*MemoryStore) StoreExpire

func (ms *MemoryStore) StoreExpire(key []byte, data []byte, expiration time.Time) error

StoreExpire stores the key-value pair and deletes it after the expiration time.

type PogrebStore

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

PogrebStore is a key-value store using Pogreb. Expiration is currently not supported.

func NewPogrebStore

func NewPogrebStore(filename string) (store *PogrebStore, err error)

NewPogrebStore create a properly initialized Pogreb store.

func (*PogrebStore) Count

func (store *PogrebStore) Count() uint64

Count returns the count of records stored.

func (*PogrebStore) Delete

func (store *PogrebStore) Delete(key []byte)

Delete deletes a key-value pair.

func (*PogrebStore) ExpireKeys

func (store *PogrebStore) ExpireKeys()

func (*PogrebStore) Get

func (store *PogrebStore) Get(key []byte) (data []byte, found bool)

Get returns the value for the key if present.

func (*PogrebStore) Iterate

func (store *PogrebStore) Iterate(callback func(key, value []byte))

Iterate iterates over all records.

func (*PogrebStore) Set

func (store *PogrebStore) Set(key []byte, data []byte) error

Store stores the key-value pair.

func (*PogrebStore) StoreExpire

func (store *PogrebStore) StoreExpire(key []byte, data []byte, expiration time.Time) error

StoreExpire stores the key-value pair and deletes it after the expiration time.

type Store

type Store interface {
	// Set stores the key-value pair.
	Set(key []byte, data []byte) error

	// StoreExpire stores the key-value pair and deletes it after the expiration time.
	// If key-value already exists, it will be overwritten and the new expiration time applies.
	StoreExpire(key []byte, data []byte, expiration time.Time) error

	// Get returns the value for the key if present.
	Get(key []byte) (data []byte, found bool)

	// Delete deletes a key-value pair.
	Delete(key []byte)

	// ExpireKeys is called to delete all keys that are marked for expiration.
	ExpireKeys()

	// Count returns the total number of records stored.
	Count() uint64

	// Iterate iterates over all records.
	Iterate(callback func(key, value []byte))
}

Store is the interface for implementing the storage mechanism for the DHT.

Jump to

Keyboard shortcuts

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