simplekv

package module
v0.0.0-...-905c55b Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: MIT Imports: 11 Imported by: 0

README

simplekv

A simple persistent key-value store


IMPORTANT NOTE: This is not production ready, just an experiment


Example Usages
package main

import (
	"fmt"
	"github.com/tcfw/simplekv"
)

func main() {
	store, _ := simplekv.NewStore("my_test.db")

	//Add a key
	store.Add([]byte("test_key"), []byte("my value"))

	//Delete a key
	store.Delete([]byte("test_key"))

	//Update a key
	store.Add([]byte("update_key"), []byte("my value"))
	store.Update([]byte("update_key"), []byte("my other value"))

	//Iterate over all keys
	for kv := range store.Iter() {
		fmt.Printf("Key: %s, Value: %s", kv.Key, kv.Value)
	}

	//Clean up deleted records
	store.Clean()
}

Documentation

Index

Constants

View Source
const (

	//FlagRecordsCompressed Records are compressed
	FlagRecordsCompressed = 0x1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IterKeyVal

type IterKeyVal struct {
	Key   []byte
	Value []byte
	Tx    uint64
}

IterKeyVal holds key values for the iter func

type Store

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

Store basic store

func NewStore

func NewStore(filename string) (*Store, error)

NewStore creates or opens a store given a file filename

func NewStoreWithBackend

func NewStoreWithBackend(be storeBackend) (*Store, error)

NewStoreWithBackend creates or opens a store from a given backend (e.g. a file on disk)

func (*Store) Add

func (s *Store) Add(key []byte, value []byte) error

Add adds a new key with given value

func (*Store) Clean

func (s *Store) Clean() error

Clean removes old tombstoned records

func (*Store) Close

func (s *Store) Close() error

Close closes the backend src and cleans records in mem

func (*Store) Delete

func (s *Store) Delete(key []byte) error

Delete dletes a key

func (*Store) Get

func (s *Store) Get(key []byte) ([]byte, error)

Get retreives the value for a given key

func (*Store) HasKey

func (s *Store) HasKey(key []byte) bool

HasKey checks if a key exists

func (*Store) Iter

func (s *Store) Iter() <-chan IterKeyVal

Iter iterates over all keys

func (*Store) Update

func (s *Store) Update(key []byte, value []byte) error

Update updates an existing key

Jump to

Keyboard shortcuts

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