store

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 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 FindWithLimit added in v0.17.2

func FindWithLimit(limit int) FindOption

FindWithLimit sets the limit for the find pattern.

func FindWithOffset added in v0.17.2

func FindWithOffset(offset int) FindOption

FindWithOffset sets the offset for the find pattern.

func FindWithPrefix added in v0.17.2

func FindWithPrefix(prefix string) FindOption

FindWithPrefix sets the prefix for the find pattern.

func FindWithSuffix added in v0.17.2

func FindWithSuffix(suffix string) FindOption

FindWithSuffix sets the suffix for the find pattern.

type FindPattern

type FindPattern struct {
	// Suffix defines the search suffix.
	Suffix string
	// Prefix defines the search prefix.
	Prefix string
	// Limit limits the result maximum records number.
	Limit int
	// Offset shifts results with an integer offset.
	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