memkv

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2017 License: MIT Imports: 6 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

memkv

Simple in memory k/v store.

Build Status GoDoc codecov

Usage

package main

import (
	"fmt"
	"log"

	"github.com/HeavyHorst/memkv"
)

func main() {
	s := memkv.New()
	s.Set("/myapp/database/username", "admin")
	s.Set("/myapp/database/password", "123456789")
	s.Set("/myapp/port", "80")
	kv, err := s.Get("/myapp/database/username")	
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Key: %s, Value: %s\n", kv.Key, kv.Value)
	ks, err := s.GetAll("/myapp/*/*")
	if err == nil {
		for _, kv := range ks {
			fmt.Printf("Key: %s, Value: %s\n", kv.Key, kv.Value)
		}
	}
}

Key: /myapp/database/username, Value: admin
Key: /myapp/database/password, Value: 123456789
Key: /myapp/database/username, Value: admin

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotExist = errors.New("key does not exist")

Functions

This section is empty.

Types

type KVPair

type KVPair struct {
	Key   string
	Value string
}

type KVPairs

type KVPairs []KVPair

func (KVPairs) Len

func (ks KVPairs) Len() int

func (KVPairs) Less

func (ks KVPairs) Less(i, j int) bool

func (KVPairs) Swap

func (ks KVPairs) Swap(i, j int)

type KeyError

type KeyError struct {
	Key string
	Err error
}

func (*KeyError) Error

func (e *KeyError) Error() string

type Store

type Store struct {
	FuncMap map[string]interface{}
	sync.RWMutex
	// contains filtered or unexported fields
}

A Store represents an in-memory key-value store safe for concurrent access.

func New

func New() *Store

func (*Store) Del

func (s *Store) Del(key string)

Del deletes the KVPair associated with key.

func (*Store) Exists

func (s *Store) Exists(key string) bool

Exists checks for the existence of key in the store.

func (*Store) Get

func (s *Store) Get(key string) (KVPair, error)

Get gets the KVPair associated with key. If there is no KVPair associated with key, Get returns KVPair{}, ErrNotExist.

func (*Store) GetAll

func (s *Store) GetAll(pattern string) (KVPairs, error)

GetAll returns a KVPair for all nodes with keys matching pattern. The syntax of patterns is the same as in path.Match.

func (*Store) GetAllKVs

func (s *Store) GetAllKVs() KVPairs

GetAllKVs returns all KV-Pairs

func (*Store) GetAllValues

func (s *Store) GetAllValues(pattern string) ([]string, error)

func (*Store) GetValue

func (s *Store) GetValue(key string, v ...string) (string, error)

GetValue gets the value associated with key. If there are no values associated with key, GetValue returns "", ErrNotExist.

func (*Store) List

func (s *Store) List(filePath string) []string

List returns all keys prefixed with filePath.

func (*Store) ListDir

func (s *Store) ListDir(filePath string) []string

ListDir returns all directories prefixed with filePath.

func (*Store) Purge

func (s *Store) Purge()

Purge removes all keys from the store.

func (*Store) Set

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

Set sets the KVPair entry associated with key to value.

Jump to

Keyboard shortcuts

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