Documentation ¶
Overview ¶
Package libkv provides key value storage for embedded go application.
Package libkv provides key value storage for embedded go application.
Index ¶
- Constants
- type Event
- type Store
- func (s *Store) Close()
- func (s *Store) Del(iden string)
- func (s *Store) Expire(iden string, exp time.Time) bool
- func (s *Store) Get(iden string) (x interface{})
- func (s *Store) Getexp(iden string, exp time.Time) (x interface{})
- func (s *Store) Getset(iden string, x interface{}) (y interface{})
- func (s *Store) IterateR() (it <-chan *Value)
- func (s *Store) IterateW() (it <-chan *Value, mod chan<- *Value)
- func (s *Store) Key() (items []string)
- func (s *Store) Keyexp() (items []string)
- func (s *Store) Lpush(iden string, x interface{}) (size int64)
- func (s *Store) Lrange(iden string, start, stop int64) (items []interface{})
- func (s *Store) Ltrim(iden string, start, stop int64) (size int64)
- func (s *Store) Save(path string) error
- func (s *Store) Set(iden string, x interface{}) (ret bool)
- func (s *Store) Setexp(iden string, x interface{}, exp time.Time) (ret bool)
- func (s *Store) TTL(iden string) (in time.Duration)
- func (s *Store) Watch(stop <-chan struct{}) <-chan *Event
- type Value
Constants ¶
const ( KV_FILE = "kv.db" KV_IDX_FILE = "kv.idx" )
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 ¶
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 ¶
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) Lpush ¶
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) Ltrim ¶
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 ¶
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) Setexp ¶
Set puts an aribtrary item x into Store identified by iden to be expired at exp