tbkv

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 1 Imported by: 0

README

tests continuous semgrep

TBKV key-val store

You're looking at a simple zero-dependency in-memory key-value store for Golang.

All operations (Get/Set/Delete) are executed in a single, buffered loop, so the store provides some thread safety.

The package is continuously scanned by semgrep and various static code critics to maintain healthy security posture.

The main tbkv package has 100% test coverage and my aim is to maintain that. The examples are covered to the extent of checking if the scenario runs successfully.

Usage


import (
	"github.com/tech-branch/tbkv"
)

func main() {
    kvs := NewDefaultStore()

    kvs.Set("key", "value")

    val, err := kvs.Get("key")
    if err != nil {
        return err
    }

    // val == "value"

    kvs.Delete("key")

    val, err := kvs.Get("key")
    if err != nil {
        // err == tbkv.ErrNotFound
        return err
    }
}

See a more complete example in ./examples/main.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("key not found")

Functions

This section is empty.

Types

type Item

type Item struct {
	Key   string
	Value string
}

type ItemRequest

type ItemRequest struct {
	Item Item
	Ok   chan bool
}

type KVStore

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

func NewDefaultStore

func NewDefaultStore() KVStore

NewDefaultStore is a convenience function for creating a KVStore with sensible defaults. It will create a KVStore with a request buffer size of 20.

func NewStore

func NewStore(requestBufferSize uint8) KVStore

NewStore creates a new KVStore. requestBufferSize is the size of the request buffer. If requestBufferSize is 0, it will use a default of 20.

func (*KVStore) Delete

func (s *KVStore) Delete(key string)

func (*KVStore) Get

func (s *KVStore) Get(key string) (string, error)

func (*KVStore) Set

func (s *KVStore) Set(key, value string)

type Request

type Request struct {
	Key    string
	Result chan Result
}

type Result

type Result struct {
	Value string
	Ok    bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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