iflytek/astron-agent · error · ValueError
Redis address is not set in environment variables
Error message
Redis address is not set in environment variables
What it means
init_data_base initializes the module-level Redis singleton, requiring a Redis address from either REDIS_CLUSTER_ADDR_KEY or REDIS_ADDR_KEY. If neither is set it raises ValueError; it also optionally reads the password and constructs a RedisService (cluster or standalone).
Solutions
- Set REDIS_CLUSTER_ADDR (e.g. redis://host:6379 or a comma-separated cluster list) or REDIS_ADDR in the environment before starting the service
- Set REDIS_PASSWORD too if the Redis instance requires auth (it is read after the address check)
- Check const.py to confirm the exact env var names the code expects and align your deployment config
- For tests, monkeypatch/set os.environ with a test Redis address in fixtures, as the existing tests do
Example fix
// before $ uvicorn app:start ValueError: Redis address is not set in environment variables // after # .env / deployment env REDIS_CLUSTER_ADDR=redis://redis-master:6379 REDIS_PASSWORD=secret
Defensive patterns
Strategy: validation
Validate before calling
import os
if not (os.getenv('REDIS_CLUSTER_ADDR') or os.getenv('REDIS_ADDR')):
raise SystemExit('Set REDIS_CLUSTER_ADDR or REDIS_ADDR before starting') Try / catch
try:
init_data_base()
except ValueError as e:
logger.error('Redis init failed: %s — configure REDIS_ADDR/REDIS_CLUSTER_ADDR', e)
raise Prevention
- Provision Redis connection vars in every deployment environment
- When moving between cluster and standalone Redis, update the matching env var
- Provide a test fixture that sets a dummy Redis address for unit tests
- Check const.py for the authoritative env var names rather than guessing
When it happens
Trigger: spark_link_app -> init_data_base runs at app creation, or tests call init_data_base directly, with both REDIS_CLUSTER_ADDR and REDIS_ADDR absent/empty in the environment.
Common situations: Redis env vars not provisioned in the container/deployment; running unit or local tests without a .env loaded; switching between cluster and single-node Redis and removing the old variable without setting the new one; empty-string values that fail the walrus truthiness check.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- SERVICE_PORT_KEY is not set
- LOG_PATH_KEY is not set
- WORKFLOW_INTERNAL_API_KEY must contain a non-default value…
- -1
- RUN_LINK_URL is not set
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/99a48813c47805e7.
Report an issue: GitHub.
Appendix: source
Thrown at core/plugin/link/domain/models/manager.py:44
"?charset=utf8mb4"
)
base_engine = create_engine(
f"mysql+pymysql://{user}:{password}@{mysql_host}:{mysql_port}"
)
with base_engine.connect() as conn:
conn.execute(text(f"CREATE DATABASE IF NOT EXISTS `{db}`"))
conn.commit()
base_engine.dispose()
data_base_singleton = DatabaseService(database_url=db_url)
# Initialize Redis service using global singleton pattern
# Use global statement to modify module-level singleton instance
global redis_singleton
if not (
addr := os.getenv(const.REDIS_CLUSTER_ADDR_KEY)
or os.getenv(const.REDIS_ADDR_KEY)
):
raise ValueError("Redis address is not set in environment variables")
password = os.getenv(const.REDIS_PASSWORD_KEY)
redis_singleton = RedisService(cluster_addr=addr, password=password)
def get_db_engine() -> Optional[DatabaseService]:
"""
Get the global database service singleton instance.
Returns:
DatabaseService: The initialized database service instance
"""
return data_base_singleton
def get_redis_engine() -> Optional[RedisService]:
"""
Get the global Redis service singleton instance.View on GitHub (pinned to 5e758547a8)