GitHub user dosubot[bot] added a comment to the discussion: Async Queries redis 
connection error

<!-- Answer -->
If Superset is still trying to connect to Redis at localhost:6379, even though 
you set the correct extraEnv, the most common cause is that your 
configOverrides (the Python code in superset_config.py) is not actually 
referencing the environment variables at runtime. In Kubernetes, setting 
extraEnv only makes the variables available to the container—they must also be 
explicitly read in your configOverrides using os.environ.get or os.getenv. If 
you use just REDIS_HOST in your configOverrides without os.environ.get, it will 
default to 'localhost' unless you define REDIS_HOST earlier in the file.

Double-check that your configOverrides look like this:

```python
import os

REDIS_HOST = os.environ.get("REDIS_HOST", "localhost")
REDIS_PORT = os.environ.get("REDIS_PORT", "6379")
REDIS_DB = os.environ.get("REDIS_DB", "1")
REDIS_CELERY_DB = os.environ.get("REDIS_CELERY_DB", "0")

CELERY_CONFIG = {
    'broker_url': f'redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CELERY_DB}',
    'result_backend': f'redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CELERY_DB}',
    # ...
}

CACHE_CONFIG = {
    'CACHE_TYPE': 'RedisCache',
    'CACHE_DEFAULT_TIMEOUT': 300,
    'CACHE_KEY_PREFIX': 'superset_',
    'CACHE_REDIS_HOST': REDIS_HOST,
    'CACHE_REDIS_PORT': REDIS_PORT,
    'CACHE_REDIS_DB': REDIS_DB,
    'CACHE_REDIS_URL': f'redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}',
}
```

If you reference REDIS_HOST directly without assigning it from os.environ.get, 
Python will not know its value and will fall back to the default in the main 
config, which is localhost. This is a subtle but common pitfall in Kubernetes 
deployments with Superset 
[[docs](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/docs/docs/installation/kubernetes.mdx)].

If you have already done this and it still fails, check that the environment 
variables are present in the running pod (`kubectl exec <pod> -- env | grep 
REDIS`) and that you can reach Redis from the pod (`kubectl exec <pod> -- nc 
-vz superset-redis-master 6379`). If DNS is an issue, try using the Redis 
service's IP address instead of the DNS name as a test 
[[troubleshooting](https://github.com/apache/superset/issues/31904#issuecomment-2598422011)].

If Redis requires a password or SSL, make sure those are included in your 
config as well. Let me know if you want a checklist for network troubleshooting 
or more details on the configOverrides pattern.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/45163d1b-ef09-45a1-bc9a-444ee8a539b1?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/45163d1b-ef09-45a1-bc9a-444ee8a539b1?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/45163d1b-ef09-45a1-bc9a-444ee8a539b1?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/45163d1b-ef09-45a1-bc9a-444ee8a539b1?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/45163d1b-ef09-45a1-bc9a-444ee8a539b1?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/45163d1b-ef09-45a1-bc9a-444ee8a539b1?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/45163d1b-ef09-45a1-bc9a-444ee8a539b1?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat
 with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&
 nbsp;[![Join 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/34650)

GitHub link: 
https://github.com/apache/superset/discussions/34650#discussioncomment-14080919

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: 
notifications-unsubscr...@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to