libkv

package
v0.0.0-...-5df59a4 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2015 License: MIT Imports: 7 Imported by: 3

Documentation

Overview

Package libkv provides key value storage for embedded go application.

Package libkv provides key value storage for embedded go application.

Index

Constants

View Source
const (
	KV_FILE     = "kv.db"
	KV_IDX_FILE = "kv.idx"
)
View Source
const (
	GET int = iota
	SET
	DEL
	EXPIRE
	GONE
	GETSET
	LPUSH
	LTRIM
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Action int    `desc: action taken e.g. GET, SET, EXPIRE`
	Iden   string `desc: key that was affected`
}

Event delivers keyspace changes to registerd Watcher

type Store

type Store struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Store is a simple key value in memory storage. Upon initialization, Store provides general get, set, del, list operations, as well as the ability to expire a key and watch a key change.

func Load

func Load(path string) (*Store, error)

Load restores kv object from file. Method is protected by mutex to prevent multiple Load job. NOTE: this is an experimental feature

func NewStore

func NewStore() (s *Store)

NewStore creates a Store object. Store object is fully initialzed upon creation.

func (*Store) Close

func (s *Store) Close()

Close stops the Store scheduler and event hub.

func (*Store) Del

func (s *Store) Del(iden string)

Del removes the item identified by iden from Store

func (*Store) Expire

func (s *Store) Expire(iden string, exp time.Time) bool

Expire puts item identified by iden to expire at exp

func (*Store) Get

func (s *Store) Get(iden string) (x interface{})

Get retrieves an item x identified by iden

func (*Store) Getexp

func (s *Store) Getexp(iden string, exp time.Time) (x interface{})

Getexp retrieves an item x identified by iden and set expiration

func (*Store) Getset

func (s *Store) Getset(iden string, x interface{}) (y interface{})

Getset retrieves an item y identified by iden and replace it with item x

func (*Store) IterateR

func (s *Store) IterateR() (it <-chan *Value)

IterateR provides iteration construct to loop over key in read only mode

func (*Store) IterateW

func (s *Store) IterateW() (it <-chan *Value, mod chan<- *Value)

IterateW provides iteration construct to loop over key set and modify

func (*Store) Key

func (s *Store) Key() (items []string)

Key retrieves the full list of item key in Store.

func (*Store) Keyexp

func (s *Store) Keyexp() (items []string)

Keyexp retrieves the full list of item key in Store that has an expiration.

func (*Store) Lpush

func (s *Store) Lpush(iden string, x interface{}) (size int64)

Lpush appends an item to item identified by iden creates new list item returns size of the item after operation; -1 for failed attempt

func (*Store) Lrange

func (s *Store) Lrange(iden string, start, stop int64) (items []interface{})

Lrange returns a slice of items within start and stop.

func (*Store) Ltrim

func (s *Store) Ltrim(iden string, start, stop int64) (size int64)

Ltrim keeps items specified in start and stop range and remove all other items. start and stop can be negative values. If the value is -1, it indicates the end of list; if it is greater then the actual length, it is clamped to the boundary beteween 0 and length of item returns size of the item after operation; -1 for failed attempt

func (*Store) Save

func (s *Store) Save(path string) error

Save stores the kv object and kv index object to designated path kv object is put under read lock to prevent changes Method is protected by mutex to prevent multiple Save job. NOTE: this is an experimental feature. Method best invoked in goroutine

func (*Store) Set

func (s *Store) Set(iden string, x interface{}) (ret bool)

Set puts an aribtrary item x into Store identified by iden

func (*Store) Setexp

func (s *Store) Setexp(iden string, x interface{}, exp time.Time) (ret bool)

Set puts an aribtrary item x into Store identified by iden to be expired at exp

func (*Store) TTL

func (s *Store) TTL(iden string) (in time.Duration)

TTL reports the life time left on the item identified by iden

func (*Store) Watch

func (s *Store) Watch(stop <-chan struct{}) <-chan *Event

Watch provides interested party to monitor keyspace changes. A Watcher (caller of Watch function) provides a stopping condition, and gets a channel for future Event in keyspace. Stop a Watcher by closeing the stop channel

type Value

type Value struct {
	K string
	X interface{}
	R bool
}

Jump to

Keyboard shortcuts

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