Skip to content

feat: added configurable redis cache for shared redis instances#7529

Open
SahilJat wants to merge 1 commit into
Flagsmith:mainfrom
SahilJat:feat/add-configurable-redis-cache
Open

feat: added configurable redis cache for shared redis instances#7529
SahilJat wants to merge 1 commit into
Flagsmith:mainfrom
SahilJat:feat/add-configurable-redis-cache

Conversation

@SahilJat
Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • [ x ] I have read the Contributing Guide.
  • [ x ] I have added information to docs/ if required so people know about the feature.
  • [ x] I have filled in the "Changes" section below.
  • [ x ] I have filled in the "How did you test this code" section below.

Changes

Closes #7297

Adds a CACHE_KEY_PREFIX environment variable that sets KEY_PREFIX on all Redis-backed cache entries in the CACHES dict.

  • Added CACHE_KEY_PREFIX = env.str("CACHE_KEY_PREFIX", default="") to api/app/settings/common.py
  • Added a loop after all CACHES entries are defined (including SAML) that applies KEY_PREFIX = CACHE_KEY_PREFIX to any cache whose BACKEND contains "redis" (case-insensitive)
  • Non-Redis backends (locmem, db, dummy) are unaffected
  • Default is empty string which preserves existing Django behaviour — no breaking change for existing deployments

With CACHE_KEY_PREFIX=flagsmith, Redis keys become flagsmith:1:environment_document_xxx instead of :1:environment_document_xxx, enabling Redis ACL rules like ~flagsmith:* for namespace-based multi-tenancy.

How did you test this code?

  • Added two unit tests in api/tests/unit/app/test_unit_app_settings.py:
    • Verifies Redis-backed caches get KEY_PREFIX applied
    • Verifies non-Redis caches (locmem, db) are not affected
    • Verifies empty prefix (default) sets KEY_PREFIX to empty string
  • Verified settings load correctly with CACHE_KEY_PREFIX=flagsmith python -c "from app.settings.common import CACHES"
  • All existing tests in api/tests/unit/app/ pass

@SahilJat SahilJat requested a review from a team as a code owner May 18, 2026 04:41
@SahilJat SahilJat requested review from emyller and removed request for a team May 18, 2026 04:41
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 2026

@SahilJat is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the api Issue related to the REST API label May 18, 2026
@SahilJat SahilJat force-pushed the feat/add-configurable-redis-cache branch from fa0db2b to 5c033c9 Compare May 18, 2026 04:47
@SahilJat SahilJat force-pushed the feat/add-configurable-redis-cache branch from 5c033c9 to 3c1c294 Compare May 18, 2026 04:51
@SahilJat
Copy link
Copy Markdown
Contributor Author

Hii alll the test cases has been passed , the test that failed is already exisiting issue mentioned here #7368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add configurable Redis cache KEY_PREFIX for shared Redis deployments

1 participant