kvstore

package module
v0.0.0-...-7e86500 Latest Latest
Warning

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

Go to latest
Published: May 6, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// NumStores is how many buckets to divide between
	NumStores uint32 = 64
	// NumReapers is how many concurrent buckets to reap at a time
	NumReapers uint8 = 4
)

Functions

This section is empty.

Types

type KVStore

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

KVStore is our primary key-value store. It is a parent container/controller used for all operations Do not use the empty value of this struct, it will panic. Use NewKVStore()

func NewKVStore

func NewKVStore() KVStore

NewKVStore inits the internal map and returns a KVStore

func (*KVStore) Delete

func (kvs *KVStore) Delete(key string)

Delete deletes the key from the store

func (*KVStore) Get

func (kvs *KVStore) Get(key string) (interface{}, bool)

Get gets the value stored at key, and whether or not it existed Always check the existed value, as the return value will always be nil if it's false

func (*KVStore) Keys

func (kvs *KVStore) Keys() []string

Keys returns all of the keys in a slice This is used for iterating, as one can use a Get on each key

func (*KVStore) Len

func (kvs *KVStore) Len() int

Len returns a rough approximation of how many items total are in the kvstore

func (*KVStore) Reap

func (kvs *KVStore) Reap(results bool) map[string]interface{}

Reap stops the world to scan the entire map and evicts expired things. results is whether or not to collect deleted keys for return If results is false, the returned map will always be nil It does not run automatically, and is meant to be user implementable.

func (*KVStore) Set

func (kvs *KVStore) Set(key string, value interface{}, ttl time.Duration)

Set sets the given key to value. If ttl is 0, it never expires. Otherwise, it expires at insertion time + duration

func (*KVStore) SetNX

func (kvs *KVStore) SetNX(key string, value interface{}, ttl time.Duration) bool

SetNX sets only if key doesn't exist. It returns whether or not the operation was successful. In other words, if the key existed, you get back false

Jump to

Keyboard shortcuts

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