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 ¶
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.