dify - ✅(Solved) Fix Support Redis Namspacing via Key Prefix Configuration [1 pull requests, 1 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#35138Fetched 2026-04-17 08:21:40
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
1
Participants
Timeline (top)
cross-referenced ×3closed ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #35139: feat: support configurable redis key prefix

Description (problem / solution / changelog)

[!IMPORTANT]

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fixes #35138 Fixes #13652 Fixes #13604

This PR adds support for configurable Redis key prefixing via REDIS_KEY_PREFIX to improve namespace isolation when multiple Dify deployments share the same Redis instance.

Main changes:

  • Added centralized Redis name helpers for prefix normalization and serialization.
  • Applied key prefixing to RedisClientWrapper operations (including lock/hash/sorted-set calls).
  • Applied prefixing to Redis-based broadcast channel names (standard, sharded, and streams).
  • Added Celery Redis transport global_keyprefix wiring to align task/broker/backend keys with the configured namespace.
  • Added REDIS_KEY_PREFIX examples in API/docker env templates and updated docker docs.
  • Added/updated unit tests for config loading, Redis naming behavior, wrapper prefixing, pub/sub channels, streams channels, and Celery transport behavior.

Compatibility notes:

  • If REDIS_KEY_PREFIX is unset or whitespace-only, behavior is unchanged from today.
  • Existing deployments can opt into namespace isolation by setting a non-empty prefix.

From Codex.

Screenshots

Before

keys without a global prefix: <img width="2490" height="1672" alt="image" src="https://github.com/user-attachments/assets/c8128f42-542a-4dad-aa49-5ec93c71bbca" />

After

keys with a global prefix, all grouped together nicely:

<img width="2580" height="1574" alt="image" src="https://github.com/user-attachments/assets/1401981f-2a22-4ad1-a02e-4f8add5ed378" />

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

Changed files

  • api/.env.example (modified, +3/-0)
  • api/configs/middleware/cache/redis_config.py (modified, +5/-0)
  • api/extensions/ext_celery.py (modified, +21/-3)
  • api/extensions/ext_redis.py (modified, +153/-64)
  • api/extensions/redis_names.py (added, +32/-0)
  • api/libs/broadcast_channel/redis/channel.py (modified, +4/-2)
  • api/libs/broadcast_channel/redis/sharded_channel.py (modified, +4/-2)
  • api/libs/broadcast_channel/redis/streams_channel.py (modified, +2/-1)
  • api/libs/db_migration_lock.py (modified, +4/-1)
  • api/tests/integration_tests/.env.example (modified, +1/-0)
  • api/tests/unit_tests/configs/test_dify_config.py (modified, +35/-0)
  • api/tests/unit_tests/extensions/test_celery_ssl.py (modified, +87/-0)
  • api/tests/unit_tests/extensions/test_pubsub_channel.py (modified, +2/-0)
  • api/tests/unit_tests/extensions/test_redis.py (modified, +100/-1)
  • api/tests/unit_tests/libs/broadcast_channel/redis/test_channel_unit_tests.py (modified, +44/-0)
  • api/tests/unit_tests/libs/broadcast_channel/redis/test_streams_channel_unit_tests.py (modified, +20/-0)
  • docker/.env.example (modified, +3/-0)
  • docker/README.md (modified, +1/-0)
  • docker/docker-compose.yaml (modified, +1/-0)
RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • 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.
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

When deploying multiple Dify instances into the same infrastructure, Redis is often shared across environments (for example, staging + production, or multiple tenants).
Without a configurable key namespace, several runtime components can write into overlapping Redis keys/channels, which increases the risk of collisions and cross-instance interference.

In this change, I implemented support for a configurable REDIS_KEY_PREFIX and applied it consistently to core Redis operations and Celery Redis transport usage. The goal is safer isolation when Redis is shared, while keeping default behavior unchanged when no prefix is configured.

2. Additional context or comments

Proposed implementation and validation scope:

  • Add REDIS_KEY_PREFIX to environment examples and docker docs.
  • Normalize prefix handling (strip) and apply prefix:key naming only when non-empty.
  • Prefix Redis client wrapper operations (get, set, delete, lock, hash/sorted-set operations, etc.).
  • Prefix pub/sub and streams broadcast channel names.
  • Apply Celery global_keyprefix transport option when Redis broker/backend is used.
  • Keep backward compatibility when prefix is empty or whitespace-only.
  • Add/extend unit tests for prefix normalization, key serialization, wrapper behavior, broadcast channels, Celery transport options, and config loading.

3. Can you help us with this feature?

  • I am interested in contributing to this feature.

extent analysis

TL;DR

Implementing a configurable REDIS_KEY_PREFIX can help prevent key collisions and cross-instance interference when sharing Redis across environments.

Guidance

  • Review the proposed implementation scope to ensure all Redis operations and Celery Redis transport usage are updated to use the REDIS_KEY_PREFIX.
  • Verify that the REDIS_KEY_PREFIX is properly normalized (e.g., stripped of whitespace) and applied consistently across all Redis client wrapper operations and broadcast channel names.
  • Test the implementation with various prefix values, including empty or whitespace-only prefixes, to ensure backward compatibility.
  • Update environment examples, Docker docs, and unit tests to reflect the new REDIS_KEY_PREFIX configuration option.

Example

No code snippet is provided as the issue does not contain specific code examples.

Notes

The implementation should ensure that the REDIS_KEY_PREFIX is applied correctly to all Redis operations, including pub/sub and streams broadcast channel names, to prevent key collisions and cross-instance interference.

Recommendation

Apply the proposed implementation of the configurable REDIS_KEY_PREFIX to prevent key collisions and cross-instance interference when sharing Redis across environments. This change will provide safer isolation while maintaining default behavior when no prefix is configured.

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