kv

package
v2.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTypeForStorage

func RegisterTypeForStorage(val interface{})

RegisterTypeForStorage registers a custom type (e.g. a struct) for use in the key value store. This is necessary if you intend to pass custom structs to Store.Set() rather than primitive types.

Types

type Store

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

Store provides an in-memory key/value store which is persisted to a file. The file handle itself is not kept locked for the duration; it is only locked during load and save, to make it concurrency friendly. When saving, the store uses optimistic locking to determine whether the db on disk has been modified by another process; in which case it loads the latest version and re-applies modifications made during this session. This means the Lost Update db concurrency issue is possible; so don't use this if you need more DB integrity than Read Committed isolation levels.

func NewStore

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

NewStore creates a new key/value store and initialises it with contents from the named file, if it exists

func (*Store) Get

func (k *Store) Get(key string) interface{}

Get retrieves a value from the store, or nil if it is not present

func (*Store) Remove

func (k *Store) Remove(key string)

Remove removes the key and its value from the store in memory Changes are not persisted until you call Save()

func (*Store) RemoveAll

func (k *Store) RemoveAll()

RemoveAll removes all entries from the store These changes are not persisted until you call Save()

func (*Store) Save

func (k *Store) Save() error

Save persists the changes made to disk If any changes have been written by other code they will be merged

func (*Store) Set

func (k *Store) Set(key string, value interface{})

Set updates the key/value store in memory Changes are not persisted until you call Save()

func (*Store) Visit

func (k *Store) Visit(cb func(string, interface{}) bool)

Visit walks through the entire store via a function; return false from your visitor function to halt the walk

Jump to

Keyboard shortcuts

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