{"record":{"id":"8f68d640609d51bf","repo":"hsliuping/TradingAgents-CN","slug":"redis-n1-redis-connection-s","errorCode":null,"errorMessage":"Redis连接配置未完整设置。请设置以下环境变量之一：\\n1. REDIS_CONNECTION_STRING=redis://localhost:6379/0\\n2. REDIS_HOST + REDIS_PORT (例如: REDIS_HOST=localhost, REDIS_PORT=6379)","messagePattern":"Redis连接配置未完整设置。请设置以下环境变量之一：\\\\n1\\. REDIS_CONNECTION_STRING=redis://localhost:6379/0\\\\n2\\. REDIS_HOST \\+ REDIS_PORT \\(例如: REDIS_HOST=localhost, REDIS_PORT=6379\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"tradingagents/config/database_config.py","lineNumber":62,"sourceCode":"            Dict[str, Any]: Redis配置字典\n            \n        Raises:\n            ValueError: 当必要的配置未设置时\n        \"\"\"\n        # 优先使用连接字符串\n        connection_string = os.getenv('REDIS_CONNECTION_STRING')\n        if connection_string:\n            return {\n                'connection_string': connection_string,\n                'database': int(os.getenv('REDIS_DATABASE', 0))\n            }\n        \n        # 使用分离的配置参数\n        host = os.getenv('REDIS_HOST')\n        port = os.getenv('REDIS_PORT')\n        \n        if not host or not port:\n            raise ValueError(\n                \"Redis连接配置未完整设置。请设置以下环境变量之一：\\n\"\n                \"1. REDIS_CONNECTION_STRING=redis://localhost:6379/0\\n\"\n                \"2. REDIS_HOST + REDIS_PORT (例如: REDIS_HOST=localhost, REDIS_PORT=6379)\"\n            )\n        \n        return {\n            'host': host,\n            'port': int(port),\n            'password': os.getenv('REDIS_PASSWORD'),\n            'database': int(os.getenv('REDIS_DATABASE', 0))\n        }\n    \n    @staticmethod\n    def validate_config() -> Dict[str, bool]:\n        \"\"\"\n        验证数据库配置是否完整\n        \n        Returns:","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/hsliuping/TradingAgents-CN/blob/74783e8817d6cf6de29867880631cc555153f36b/tradingagents/config/database_config.py#L44-L80","documentation":"Raised by get_redis_config() when neither REDIS_CONNECTION_STRING nor the REDIS_HOST + REDIS_PORT pair is fully set. The function reads host/port from separate env vars and requires both, so a partial configuration is rejected.","triggerScenarios":"Calling validate_config() (which calls get_redis_config) with REDIS_HOST set but REDIS_PORT missing (or vice versa), or neither the connection string nor host/port set at all.","commonSituations":"Copy-pasted .env templates where only REDIS_HOST is defined, someone renaming variables (REDIS_URL vs REDIS_CONNECTION_STRING), or deploying with only the URL-style variable present while the code path reads host/port.","solutions":["Set both REDIS_HOST=localhost and REDIS_PORT=6379","Or set REDIS_CONNECTION_STRING=redis://localhost:6379/0 instead","Verify with: python -c \"import os; print(os.getenv('REDIS_HOST'), os.getenv('REDIS_PORT'))\""],"exampleFix":"# before\n# .env has only REDIS_HOST\n# after\nREDIS_HOST=localhost\nREDIS_PORT=6379","handlingStrategy":"validation","validationCode":"import os\nassert os.getenv('REDIS_CONNECTION_STRING') or (os.getenv('REDIS_HOST') and os.getenv('REDIS_PORT')), 'Redis config incomplete'\nvalidate_config()","typeGuard":null,"tryCatchPattern":"try:\n    cfg = get_redis_config()\nexcept ValueError as e:\n    logger.warning('Redis disabled: %s', e)\n    cfg = {'enabled': False}","preventionTips":["Document required env var pairs in README/.env.example","Validate env at boot with a small checklist function","Never set only one of REDIS_HOST/REDIS_PORT"],"tags":["python","redis","env-var","config"],"backgroundTag":"missing-env-var","analyzedSha":"74783e8817d6cf6de29867880631cc555153f36b","analyzedAt":"2026-08-28T11:39:07.729Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}