store

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Overview

Package store defines basic key value store for neuron services.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStore is the main store error.
	ErrStore = errors.New("store")
	// ErrRecordNotFound is the error when the value stored with 'key' is not found.
	// This should be implemented by all stores.
	ErrRecordNotFound = errors.Wrap(ErrStore, "record not found")
	// ErrInternal is an internal error for the stores.
	ErrInternal = errors.Wrap(errors.ErrInternal, "store")
)

Functions

This section is empty.

Types

type FindOption

type FindOption func(o *FindPattern)

FindOption is a option func that changes find pattern.

func WithFindLimit

func WithFindLimit(limit int) FindOption

WithFindLimit sets the limit for the find pattern.

func WithFindOffset

func WithFindOffset(offset int) FindOption

WithFindOffset sets the offset for the find pattern.

func WithFindPrefix

func WithFindPrefix(prefix string) FindOption

WithFindPrefix sets the prefix for the find pattern.

func WithFindSuffix

func WithFindSuffix(suffix string) FindOption

WithFindSuffix sets the suffix for the find pattern.

type FindPattern

type FindPattern struct {
	Suffix string
	Prefix string
	Limit  int
	Offset int
}

FindPattern is the pattern used for querying the store.

type Option

type Option func(o *Options)

Option is an option function that changes Options.

func WithDefaultExpiration

func WithDefaultExpiration(expiration time.Duration) Option

WithDefaultExpiration sets the default expiration option.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets the default prefix for the keys using this store.

func WithSuffix

func WithSuffix(suffix string) Option

WithSuffix sets the default suffix for the keys using this store.

type Options

type Options struct {
	// DefaultExpiration is the default expiration time that the records use.
	DefaultExpiration time.Duration
	// CleanupInterval sets the cleanup interval when the expired keys are being deleted from store.
	CleanupInterval time.Duration
	// Prefix, Suffix are the default prefix, suffix for the record key.
	Prefix, Suffix string
}

Options are the initialization options for the store.

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions creates the default store options.

type Record

type Record struct {
	// Key is the key at which the record would be stored
	Key string
	// Value is the value of the record.
	Value []byte
	// ExpiresAt defines the time when the record would be expired.
	ExpiresAt time.Time
}

Record is a single entry stored within a store.

func (*Record) Copy

func (r *Record) Copy() *Record

Copy creates a record copy.

type Store

type Store interface {
	// Set sets the record within the store. This function should replace any existing record with provided key.
	Set(ctx context.Context, record *Record) error
	// SetWithTTL sets the record with specified ttl value. This function should replace any existing record with provided key.
	SetWithTTL(ctx context.Context, record *Record, ttl time.Duration) error
	// Get gets the record stored under 'key'. If the record is not found the function should return ErrRecordNotFound.
	Get(ctx context.Context, key string) (*Record, error)
	// Delete deletes the record stored using a 'key'. If the record is not found the function should return ErrRecordNotFound.
	Delete(ctx context.Context, key string) error
	// Find finds the records stored using some specific pattern.
	Find(ctx context.Context, options ...FindOption) ([]*Record, error)
	// Close closes the store connection.
	Close(ctx context.Context) error
}

Store is an interface for key - value stores.

Directories

Path Synopsis
Package memory contains in-memory store implementation for neuron framework.
Package memory contains in-memory store implementation for neuron framework.

Jump to

Keyboard shortcuts

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