dify - ✅(Solved) Fix EVENT_BUS_REDIS_USE_CLUSTER can not handler redis cluster [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langgenius/dify#35291Fetched 2026-04-16 07:06:38
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
1
Timeline (top)
commented ×1labeled ×1mentioned ×1subscribed ×1

Error Message

If the EVENT_BUS_REDIS_* variables are not configured, according to the user manual, the system should fall back to the general Redis configuration. However, this does not work in practice, and running workflows returns a Redis connection error.

PR fix notes

PR #35338: fix(api): inherit REDIS_USE_CLUSTERS for event bus pubsub config (#35291) 🤖🤖🤖

Description (problem / solution / changelog)

Summary

Fixes #35291.

The event bus pub/sub config (PUBSUB_REDIS_* / EVENT_BUS_REDIS_*) already inherits connection details from the generic Redis config (REDIS_HOST, REDIS_PORT, REDIS_USERNAME, REDIS_PASSWORD, REDIS_DB, REDIS_USE_SSL) via the existing normalized_pubsub_redis_url property, but PUBSUB_REDIS_USE_CLUSTERS was not covered by that fallback. With the old False default, _create_pubsub_client at api/extensions/ext_redis.py:454 always invoked redis.Redis.from_url(...) — never RedisCluster.from_url(...) — even when the operator had set REDIS_USE_CLUSTERS=true for the main Redis. In cluster-only deployments this makes the event bus fail.

Three commits, all scoped to the fix:

  1. fix(api) — extend RedisConfigDefaults with REDIS_USE_CLUSTERS, change the PUBSUB_REDIS_USE_CLUSTERS default from False to None, add a computed normalized_pubsub_use_clusters property mirroring normalized_pubsub_redis_url, and route the single call site through it.
  2. fix(docker) — without this follow-up the Python-level fallback is shadowed by docker-compose.yaml injecting EVENT_BUS_REDIS_USE_CLUSTERS: ${EVENT_BUS_REDIS_USE_CLUSTERS:-false} into every container. That makes Pydantic see the literal string "false" before the new inheritance logic can fire, reproducing the bug for docker users (the reported deployment context). The .env.example and generated docker-compose.yaml defaults are now empty; a small field_validator coerces empty/whitespace-only env values to None so Pydantic does not reject "".
  3. test(ext_redis) — pin the call-site swap with three integration-style tests that patch the client factories and assert _create_pubsub_client receives the correct use_clusters kwarg. Without these, a future refactor that restores the raw PUBSUB_REDIS_USE_CLUSTERS read at init_app would silently reintroduce the bug with all existing property tests still passing.

Explicitly setting either PUBSUB_REDIS_USE_CLUSTERS or EVENT_BUS_REDIS_USE_CLUSTERS still wins over the inherited flag. Non-cluster deployments with both flags unset keep the current behavior (cluster off).

Verification

Unit tests — 8 new, all passing locally (config layer + runtime routing):

$ uv run pytest api/tests/unit_tests/configs/test_dify_config.py \
    api/tests/unit_tests/extensions/test_redis.py -q
46 passed in 4.65s

The 5 config-layer tests cover: inheritance, explicit override, pubsub-only cluster, empty-string env (docker-compose ${VAR:-} pattern), and the no-flag default. The 3 ext_redis tests assert the runtime-path swap: init_app calls _create_pubsub_client(url, True) when normalized_pubsub_use_clusters is True, ...(url, False) when explicitly False, and skips pubsub client construction when the URL is absent.

End-to-end verification against a live Redis clusterdocker run -p 7000-7005:7000-7005 grokzen/redis-cluster (3 masters + 3 replicas, all 16384 slots assigned, cluster_state:ok), then ran the same init_app code path with the operator's reported env:

Scenarioupstream/mainthis PR
REDIS_USE_CLUSTERS=true, EVENT_BUS_REDIS_USE_CLUSTERS="" <br> (the post-fix docker-compose default)ValidationError: Input should be a valid boolean, unable to interpret input [input_value=''] — API fails to startnormalized_pubsub_use_clusters=True, pubsub client is redis.cluster.RedisCluster, live PUBLISH reaches the cluster
REDIS_USE_CLUSTERS=true, EVENT_BUS_REDIS_USE_CLUSTERS="false" <br> (the pre-fix docker-compose default)Silent bug — use_clusters=False, pubsub client is standalone redis.RedisExplicit override still wins (standalone) — correct per design; this env is no longer injected by the updated compose template

Against a vanilla Redis Cluster, redis-py's standalone client transparently follows MOVED redirects for data commands, and plain PUBLISH gossip-propagates across cluster nodes — so the misrouting does not always produce a hard failure in vanilla tests. The consequential failures reported in #35291 happen on managed cluster-only endpoints (AWS ElastiCache cluster-mode, GCP Memorystore cluster-mode, Kubernetes deployments behind a single LB endpoint) that reject non-cluster-protocol connections outright. The fix is to always use the correct client type when the operator has opted into cluster mode for the main Redis.

Static checksruff format + check clean on all three files, basedpyright and mypy clean on configs/middleware/cache/redis_pubsub_config.py and extensions/ext_redis.py (Success: no issues found in 2 source files).

Screenshots

N/A — backend-only config, docker template, and test change.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

From Claude Code

Changed files

  • api/configs/middleware/cache/redis_pubsub_config.py (modified, +22/-3)
  • api/extensions/ext_redis.py (modified, +1/-1)
  • api/tests/unit_tests/configs/test_dify_config.py (modified, +104/-0)
  • api/tests/unit_tests/extensions/test_redis.py (modified, +80/-0)
  • docker/.env.example (modified, +3/-1)
  • docker/docker-compose.yaml (modified, +1/-1)
RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.13.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

When deploying version 1.13.3, I cannot use Redis Cluster for the EVENT_BUS_REDIS_* configuration.

If the EVENT_BUS_REDIS_* variables are not configured, according to the user manual, the system should fall back to the general Redis configuration. However, this does not work in practice, and running workflows returns a Redis connection error. We configure Redis Cluster using REDIS_CLUSTERS, but the EVENT_BUS_REDIS_* settings only support URL format.

✔️ Expected Behavior

can use Redis Cluster for the EVENT_BUS_REDIS_* configuration.

❌ Actual Behavior

No response

extent analysis

TL;DR

The issue can be resolved by configuring the EVENT_BUS_REDIS_* variables to support Redis Cluster using a compatible format.

Guidance

  • Verify that the EVENT_BUS_REDIS_* variables are correctly formatted to support Redis Cluster, as the current URL format may not be compatible.
  • Check the documentation for the correct format to use when configuring Redis Cluster for EVENT_BUS_REDIS_* variables.
  • Consider modifying the EVENT_BUS_REDIS_* configuration to use the REDIS_CLUSTERS format, if possible.
  • Test the configuration by running workflows and checking for Redis connection errors.

Example

No code snippet is provided as the issue does not contain enough information to create a specific example.

Notes

The issue may be specific to version 1.13.3, and the solution may vary depending on the specific Redis Cluster configuration.

Recommendation

Apply workaround: Modify the EVENT_BUS_REDIS_* configuration to support Redis Cluster using a compatible format, as the current configuration does not work as expected.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING