kvs

package
v0.0.0-...-9208368 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2017 License: Unlicense Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CollectGarbageTimeout = errors.New("CollectGarbage timed out")
View Source
var NotFound = fmt.Errorf("Key-value pair was not found")

Functions

func CollectGarbage

func CollectGarbage(c context.Context, opts *GC) (int, error)

CollectGarbage deletes expired kv entities from the datastore. This function should be called regularly to prevent expired kvs from accumulating in the datastore. Returns the number of entities that were removed from datastore.

If GC.Ttl is reached, returns CollectGarbageTimeout regardless how many entities were expired before then.

func Modify

func Modify(c context.Context, k string, f func(*KV, bool) error) error

Modify atomically changes the value of a KV by applying a function to its current value. The bool given to the callback is true if the key exists and hasn't expired, false otherwise.

The callback should return an error if it's unable to modify the value given. That error value becomes Modify's error value.

Put and Modify don't play well together. For any given key, it's best to choose one and use it exclusively for all writes. Find works well for reads in both cases.

Types

type GC

type GC struct {
	// Ttl describes how much time a single GC operation should be allowed to run.
	// This can be tuned based on how frequently GC jobs are executed.  For
	// example, if GC runs once per minute, you might set Ttl to 50 seconds.
	//
	// Ttl is only a guideline for the GC operation.  It might run longer or
	// shorter than this target.
	//
	// Defaults to 50 seconds.
	Ttl time.Duration

	// Leeway describes how far past its expiration a KV must be before it's
	// considered for garbage collection.  It should be set high enough that
	// the probability of a KV being used again is very low.
	//
	// Defaults to 24 hours.
	Leeway time.Duration
}

GC defines options for how to perform garbage collection on KV entities.

type KV

type KV struct {
	Key     string `datastore:",noindex"`
	Value   []byte `datastore:",noindex"`
	Expires time.Time

	Ttl time.Duration `datastore:"-"` // convenient alternative to Expires
}

func Find

func Find(c context.Context, k string) (*KV, error)

Find looks for an existing key-value pair. Returns NotFound if the key does not exist.

func (*KV) Compress

func (kv *KV) Compress() error

Compress rewrites the Value field by compressing it with gzip.

func (*KV) Decode

func (kv *KV) Decode(x interface{}) error

Decode extracts the Value field by gob decoding into a Go value.

func (*KV) Decompress

func (kv *KV) Decompress() error

Decompress rewrites the Value field by decompressing it with gzip.

func (*KV) Delete

func (kv *KV) Delete(c context.Context) error

Remove a rule in the datastore

func (*KV) Encode

func (kv *KV) Encode(x interface{}) error

Encode sets the Value field by gob encoding a Go value.

func (*KV) Put

func (kv *KV) Put(c context.Context) error

Put stores a key-value pair until its expiration.

Jump to

Keyboard shortcuts

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