kvstore

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeChain    = "chain"
	TypeDdb      = "ddb"
	TypeInMemory = "inMemory"
	TypeRedis    = "redis"
)

Variables

This section is empty.

Functions

func CastKeyToString

func CastKeyToString(key interface{}) (string, error)

func DdbBaseName

func DdbBaseName(settings *Settings) string

func GetConfigurableKey

func GetConfigurableKey(name string) string

func Marshal

func Marshal(v interface{}) ([]byte, error)

func RedisBasename

func RedisBasename(settings *Settings) string

func UniqKeys

func UniqKeys(keys []interface{}) ([]interface{}, error)

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Types

type ChainConfiguration

type ChainConfiguration struct {
	Project             string                `cfg:"project"`
	Family              string                `cfg:"family"`
	Group               string                `cfg:"group"`
	Application         string                `cfg:"application"`
	Type                string                `cfg:"type" default:"chain" validate:"eq=chain"`
	Elements            []string              `cfg:"elements" validate:"min=1"`
	Ddb                 DdbSettings           `cfg:"ddb"`
	Ttl                 time.Duration         `cfg:"ttl"`
	BatchSize           int                   `cfg:"batch_size" default:"100" validate:"min=1"`
	MissingCacheEnabled bool                  `cfg:"missing_cache_enabled" default:"false"`
	MetricsEnabled      bool                  `cfg:"metrics_enabled" default:"false"`
	InMemory            InMemoryConfiguration `cfg:"in_memory"`
}

type ChainKvStore

type ChainKvStore[T any] interface {
	KvStore[T]
	Add(elementFactory ElementFactory[T]) error
	AddStore(store KvStore[T])
}

func NewChainKvStore

func NewChainKvStore[T any](ctx context.Context, config cfg.Config, logger log.Logger, missingCacheEnabled bool, settings *Settings) (ChainKvStore[T], error)

func NewChainKvStoreWithInterfaces

func NewChainKvStoreWithInterfaces[T any](logger log.Logger, factory Factory[T], missingCache KvStore[T], settings *Settings) ChainKvStore[T]

type DdbDeleteItem

type DdbDeleteItem struct {
	Key string `json:"key" ddb:"key=hash"`
}

type DdbItem

type DdbItem struct {
	Key   string `json:"key" ddb:"key=hash"`
	Value string `json:"value"`
}

type DdbSettings

type DdbSettings struct {
	ClientName string `cfg:"client_name" default:"default"`
}

type ElementFactory

type ElementFactory[T any] func(ctx context.Context, config cfg.Config, logger log.Logger, settings *Settings) (KvStore[T], error)

type Factory

type Factory[T any] func(elementFactory ElementFactory[T], settings *Settings) (KvStore[T], error)

type InMemoryConfiguration

type InMemoryConfiguration struct {
	MaxSize        int64         `cfg:"max_size" default:"5000"`
	Buckets        uint32        `cfg:"buckets" default:"16"`
	ItemsToPrune   uint32        `cfg:"items_to_prune" default:"500"`
	DeleteBuffer   uint32        `cfg:"delete_buffer" default:"1024"`
	PromoteBuffer  uint32        `cfg:"promote_buffer" default:"1024"`
	GetsPerPromote int32         `cfg:"gets_per_promote" default:"3"`
	NotFoundTtl    time.Duration `cfg:"not_found_ttl" default:"0"`
}

type InMemoryKvStore

type InMemoryKvStore[T any] struct {
	// contains filtered or unexported fields
}

func (*InMemoryKvStore[T]) Contains

func (s *InMemoryKvStore[T]) Contains(_ context.Context, key any) (bool, error)

func (*InMemoryKvStore[T]) Delete

func (s *InMemoryKvStore[T]) Delete(_ context.Context, key any) error

func (*InMemoryKvStore[T]) DeleteBatch

func (s *InMemoryKvStore[T]) DeleteBatch(ctx context.Context, keys any) error

func (*InMemoryKvStore[T]) EstimateSize

func (s *InMemoryKvStore[T]) EstimateSize() *int64

func (*InMemoryKvStore[T]) Get

func (s *InMemoryKvStore[T]) Get(_ context.Context, key any, value *T) (bool, error)

func (*InMemoryKvStore[T]) GetBatch

func (s *InMemoryKvStore[T]) GetBatch(ctx context.Context, keys any, values any) ([]interface{}, error)

func (*InMemoryKvStore[T]) Put

func (s *InMemoryKvStore[T]) Put(_ context.Context, key any, value T) error

func (*InMemoryKvStore[T]) PutBatch

func (s *InMemoryKvStore[T]) PutBatch(ctx context.Context, values any) error

type InMemorySettings

type InMemorySettings struct {
	MaxSize        int64
	Buckets        uint32
	ItemsToPrune   uint32
	DeleteBuffer   uint32
	PromoteBuffer  uint32
	GetsPerPromote int32
	NotFoundTtl    time.Duration
}

type KvStore

type KvStore[T any] interface {
	// Check if a key exists in the store.
	Contains(ctx context.Context, key any) (bool, error)
	// Retrieve a value from the store by the given key. If the value does
	// not exist, false is returned and value is not modified.
	// value should be a pointer to the model you want to retrieve.
	Get(ctx context.Context, key any, value *T) (bool, error)
	// Retrieve a set of values from the store. Each value is written to the
	// map in values at its key.  Values should be something which can be converted to map[interface{}]T.
	// Returns a list of missing keys in the store.
	GetBatch(ctx context.Context, keys any, values any) ([]any, error)
	// Write a value to the store
	Put(ctx context.Context, key any, value T) error
	// Write a batch of values to the store. Values should be something which
	// can be converted to map[interface{}]T.
	PutBatch(ctx context.Context, values any) error
	// Remove the value with the given key from the store
	Delete(ctx context.Context, key any) error
	// Remove all values with the given keys from the store
	DeleteBatch(ctx context.Context, keys any) error
}

func NewConfigurableKvStore

func NewConfigurableKvStore[T any](ctx context.Context, config cfg.Config, logger log.Logger, name string) (KvStore[T], error)

func NewDdbKvStore

func NewDdbKvStore[T any](ctx context.Context, config cfg.Config, logger log.Logger, settings *Settings) (KvStore[T], error)

func NewDdbKvStoreWithInterfaces

func NewDdbKvStoreWithInterfaces[T any](repository ddb.Repository, settings *Settings) KvStore[T]

func NewEmptyKvStore

func NewEmptyKvStore[T any]() KvStore[T]

func NewEmptyKvStoreWithInterfaces

func NewEmptyKvStoreWithInterfaces[T any]() KvStore[T]

func NewInMemoryKvStore

func NewInMemoryKvStore[T any](_ context.Context, _ cfg.Config, _ log.Logger, settings *Settings) (KvStore[T], error)

func NewInMemoryKvStoreWithInterfaces

func NewInMemoryKvStoreWithInterfaces[T any](settings *Settings) KvStore[T]

func NewMetricStoreWithInterfaces

func NewMetricStoreWithInterfaces[T any](store KvStore[T], settings *Settings) KvStore[T]

func NewRedisKvStore

func NewRedisKvStore[T any](_ context.Context, config cfg.Config, logger log.Logger, settings *Settings) (KvStore[T], error)

func NewRedisKvStoreWithInterfaces

func NewRedisKvStoreWithInterfaces[T any](client redis.Client, settings *Settings) KvStore[T]

func ProvideConfigurableKvStore

func ProvideConfigurableKvStore[T any](ctx context.Context, config cfg.Config, logger log.Logger, name string) (KvStore[T], error)

type MetricStore

type MetricStore[T any] struct {
	KvStore[T]
	// contains filtered or unexported fields
}

func (*MetricStore[T]) Contains

func (s *MetricStore[T]) Contains(ctx context.Context, key any) (bool, error)

func (*MetricStore[T]) Delete

func (s *MetricStore[T]) Delete(ctx context.Context, key any) error

func (*MetricStore[T]) DeleteBatch

func (s *MetricStore[T]) DeleteBatch(ctx context.Context, keys any) error

func (*MetricStore[T]) Get

func (s *MetricStore[T]) Get(ctx context.Context, key any, value *T) (bool, error)

func (*MetricStore[T]) GetBatch

func (s *MetricStore[T]) GetBatch(ctx context.Context, keys any, result any) ([]interface{}, error)

func (*MetricStore[T]) Put

func (s *MetricStore[T]) Put(ctx context.Context, key any, value T) error

func (*MetricStore[T]) PutBatch

func (s *MetricStore[T]) PutBatch(ctx context.Context, values any) error

type Settings

type Settings struct {
	cfg.AppId
	DdbSettings    DdbSettings
	Name           string
	Ttl            time.Duration
	BatchSize      int
	MetricsEnabled bool
	InMemorySettings
}

type SizedStore

type SizedStore[T any] interface {
	KvStore[T]
	// return an estimate about how many elements are currently in the store
	// returns nil if no estimate could be returned
	EstimateSize() *int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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