{"record":{"id":"bf1e97e20f99dff0","repo":"BerriAI/litellm","slug":"either-redis-url-or-both-redis-host-and-redis","errorCode":null,"errorMessage":"Either 'REDIS_URL' or both 'REDIS_HOST' and 'REDIS_PORT' must be specified for Redis.","messagePattern":"Either 'REDIS_URL' or both 'REDIS_HOST' and 'REDIS_PORT' must be specified for Redis\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/_redis.py","lineNumber":337,"sourceCode":"            auth_response = self.read_response()\n\n        if str_if_bytes(auth_response) != \"OK\":\n            raise AuthenticationError(\"Azure AD authentication failed for Redis\")\n\n    # Attach the live credential object so async paths can wrap it in\n    # AzureADCredentialProvider for refresh-aware token retrieval. The raw\n    # client_id/tenant_id/secret are intentionally NOT exposed here — the\n    # credential closure already holds them.\n    ad_connect._azure_credential = credential\n    return ad_connect\n\n\ndef get_redis_url_from_environment():\n    if \"REDIS_URL\" in os.environ:\n        return os.environ[\"REDIS_URL\"]\n\n    if \"REDIS_HOST\" not in os.environ or \"REDIS_PORT\" not in os.environ:\n        raise ValueError(\"Either 'REDIS_URL' or both 'REDIS_HOST' and 'REDIS_PORT' must be specified for Redis.\")\n\n    if \"REDIS_SSL\" in os.environ and os.environ[\"REDIS_SSL\"].lower() == \"true\":\n        redis_protocol = \"rediss\"\n    else:\n        redis_protocol = \"redis\"\n\n    # Build authentication part of URL\n    auth_part = \"\"\n    if \"REDIS_USERNAME\" in os.environ and \"REDIS_PASSWORD\" in os.environ:\n        auth_part = f\"{os.environ['REDIS_USERNAME']}:{os.environ['REDIS_PASSWORD']}@\"\n    elif \"REDIS_PASSWORD\" in os.environ:\n        auth_part = f\"{os.environ['REDIS_PASSWORD']}@\"\n\n    return f\"{redis_protocol}://{auth_part}{os.environ['REDIS_HOST']}:{os.environ['REDIS_PORT']}\"\n\n\ndef _get_redis_client_logic(**env_overrides):\n    \"\"\"","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/_redis.py#L319-L355","documentation":"get_redis_url_from_environment() in litellm/_redis.py builds a Redis URL purely from env vars. It first checks REDIS_URL; otherwise it requires both REDIS_HOST and REDIS_PORT, raising ValueError if either is missing. REDIS_SSL=true switches the scheme to rediss, and REDIS_USERNAME/REDIS_PASSWORD are folded into the auth portion of the URL.","triggerScenarios":"Proxy/cache init calls get_redis_url_from_environment() when no explicit Redis URL/host was configured and the environment has none of REDIS_URL, or has REDIS_HOST without REDIS_PORT (or vice versa). Typical when cache: type: redis in config.yaml with the connection details expected from env that aren't set.","commonSituations":"Forgetting to export REDIS_HOST/REDIS_PORT in the shell or container; setting only REDIS_HOST assuming default port; typos in var names (REDISHOST); env file not loaded by docker-compose/systemd.","solutions":["Set REDIS_URL=redis://[[user]:pass]@host:port[/db] — a single var covers everything","Or set both REDIS_HOST and REDIS_PORT (and optionally REDIS_PASSWORD, REDIS_USERNAME, REDIS_SSL=true for TLS)","Verify the env reaches the process: docker exec ... env | grep REDIS","If Redis is optional, guard the config so cache init is skipped when env is absent"],"exampleFix":"# before\nexport REDIS_HOST=redis.internal\n# REDIS_PORT missing -> ValueError: Either 'REDIS_URL' or both 'REDIS_HOST' and 'REDIS_PORT' must be specified\n\n# after\nexport REDIS_URL=\"redis://:password@redis.internal:6379/0\"\n# or\nexport REDIS_HOST=redis.internal REDIS_PORT=6379","handlingStrategy":"validation","validationCode":"import os\n\nurl = os.environ.get(\"REDIS_URL\")\nhost, port = os.environ.get(\"REDIS_HOST\"), os.environ.get(\"REDIS_PORT\")\nif not url and not (host and port):\n    raise RuntimeError(\n        \"Redis not configured: set REDIS_URL or both REDIS_HOST and REDIS_PORT\"\n    )","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on REDIS_URL in deploy templates — one variable, fewer partial-config states","Assert required env vars in the container entrypoint before the proxy starts","Use docker-compose env_file / k8s secretRef consistently so Redis vars always reach the process"],"tags":["redis","environment-variables","configuration","cache","startup"],"backgroundTag":"missing-env-var","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}