memkv

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2017 License: MIT Imports: 5 Imported by: 153

README

memkv

Simple in memory k/v store.

Build Status GoDoc

Usage

package main

import (
	"fmt"
	"log"

	"github.com/kelseyhightower/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

Overview

Package memkv implements an in-memory key/value store.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMatch = errors.New("no keys match")
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

New creates and initializes a new Store.

func (Store) Del

func (s Store) Del(key string)

Delete 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) 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

func (Store) ListDir

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

func (Store) Purge

func (s Store) Purge()

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