{"record":{"id":"99a48813c47805e7","repo":"iflytek/astron-agent","slug":"redis-address-is-not-set-in-environment-variables","errorCode":null,"errorMessage":"Redis address is not set in environment variables","messagePattern":"Redis address is not set in environment variables","errorType":"console","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/plugin/link/domain/models/manager.py","lineNumber":44,"sourceCode":"        \"?charset=utf8mb4\"\n    )\n    base_engine = create_engine(\n        f\"mysql+pymysql://{user}:{password}@{mysql_host}:{mysql_port}\"\n    )\n    with base_engine.connect() as conn:\n        conn.execute(text(f\"CREATE DATABASE IF NOT EXISTS `{db}`\"))\n        conn.commit()\n    base_engine.dispose()\n    data_base_singleton = DatabaseService(database_url=db_url)\n\n    # Initialize Redis service using global singleton pattern\n    # Use global statement to modify module-level singleton instance\n    global redis_singleton\n    if not (\n        addr := os.getenv(const.REDIS_CLUSTER_ADDR_KEY)\n        or os.getenv(const.REDIS_ADDR_KEY)\n    ):\n        raise ValueError(\"Redis address is not set in environment variables\")\n\n    password = os.getenv(const.REDIS_PASSWORD_KEY)\n    redis_singleton = RedisService(cluster_addr=addr, password=password)\n\n\ndef get_db_engine() -> Optional[DatabaseService]:\n    \"\"\"\n    Get the global database service singleton instance.\n\n    Returns:\n        DatabaseService: The initialized database service instance\n    \"\"\"\n    return data_base_singleton\n\n\ndef get_redis_engine() -> Optional[RedisService]:\n    \"\"\"\n    Get the global Redis service singleton instance.","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/link/domain/models/manager.py#L26-L62","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n$ uvicorn app:start\nValueError: Redis address is not set in environment variables\n// after\n# .env / deployment env\nREDIS_CLUSTER_ADDR=redis://redis-master:6379\nREDIS_PASSWORD=secret","handlingStrategy":"validation","validationCode":"import os\nif not (os.getenv('REDIS_CLUSTER_ADDR') or os.getenv('REDIS_ADDR')):\n    raise SystemExit('Set REDIS_CLUSTER_ADDR or REDIS_ADDR before starting')","typeGuard":null,"tryCatchPattern":"try:\n    init_data_base()\nexcept ValueError as e:\n    logger.error('Redis init failed: %s — configure REDIS_ADDR/REDIS_CLUSTER_ADDR', e)\n    raise","preventionTips":["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"],"tags":["config","env","redis","startup"],"backgroundTag":"missing-env-var","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}