Documentation
¶
Overview ¶
Package store defines basic key value store for neuron services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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") // ErrInitialization is the error returned when the store have some issues with initialization. ErrInitialization = errors.Wrap(ErrStore, "initialization") // 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 WithConnectionURL ¶ added in v0.18.0
WithConnectionURL sets the connectionURL for the store.
func WithDefaultExpiration ¶
WithDefaultExpiration sets the default expiration option.
func WithFileName ¶ added in v0.18.0
WithFileName sets the filename setting for the store.
func WithPrefix ¶
WithPrefix sets the default prefix for the keys using this store.
func WithSuffix ¶
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
// ConnectionURL is the optional url for store connection.
ConnectionURL string
// FileName is the an optional setting when the store's temporary value are being stored.
FileName 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.
type SetOption ¶ added in v0.19.0
type SetOption func(o *SetOptions)
SetOption is an option that sets the set options.
func SetWithTTL ¶ added in v0.19.0
SetWithTTL sets the TTL while setting the record.
type SetOptions ¶ added in v0.19.0
SetOptions are the options used for setting the record.
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, options ...SetOption) 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)
}
Store is an interface for key - value stores.