store

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package store provides storage backend initialization for the forecaster.

This package acts as a factory for creating storage.Store implementations based on the forecaster configuration. It supports two storage backends:

  • Memory: In-memory storage (default) - suitable for single-instance deployments and development. Data is lost on restart.

  • Redis: Distributed Redis storage - required for multi-instance deployments and production HA setups. Provides persistence and shared state across multiple forecaster instances.

The store factory performs fail-fast initialization, validating storage connectivity during startup and exiting immediately if the backend is unavailable. This ensures the forecaster never runs with a broken storage configuration.

Usage:

store := store.New(cfg, logger)
defer func() {
    if closer, ok := store.(interface{ Close() error }); ok {
        closer.Close()
    }
}()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg *config.Config, logger *slog.Logger) storage.Store

New creates and initializes a storage backend based on the provided configuration.

The function performs fail-fast validation, establishing and verifying the storage connection during initialization. If the backend is unavailable or misconfigured, the process exits immediately with os.Exit(1).

Supported storage backends:

  • "memory": In-memory storage with optional TTL-based expiration. No external dependencies. Data lost on restart.

  • "redis": Redis-backed storage with connection pooling and health checks. Requires Redis server. Connection parameters from cfg.Redis*.

Parameters:

  • cfg: Forecaster configuration containing storage backend selection and connection parameters (RedisAddr, RedisPassword, RedisDB, RedisTTL)

  • logger: Structured logger for initialization events and errors

Returns:

storage.Store implementation ready for use. Never returns nil.
Calls os.Exit(1) on initialization failure.

Example:

store := store.New(cfg, logger)
snapshot, found, err := store.GetLatest("my-workload")

Types

This section is empty.

Jump to

Keyboard shortcuts

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