feat: add redis fallback mechanism #21043#21044
Merged
crazywoola merged 2 commits intolanggenius:mainfrom Jul 10, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a Redis fallback capability to prevent service disruptions when Redis is unavailable by introducing a decorator and applying it to rate‐limiting methods, along with tests for the decorator.
- Introduces
redis_fallbackdecorator inext_redis.pyfor handlingRedisErrorwith configurable defaults and logging - Applies the decorator to key rate‐limiting methods in
account_service.py - Adds unit tests for the fallback decorator behavior in
test_redis.py
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| api/extensions/ext_redis.py | Adds redis_fallback decorator with logging of failures |
| api/services/account_service.py | Decorates rate‐limit methods with Redis fallback logic |
| api/tests/unit_tests/extensions/test_redis.py | Introduces tests to validate the decorator functionality |
Comments suppressed due to low confidence (1)
api/services/account_service.py:498
- Add unit tests for this decorated method to confirm that it returns
Noneand logs appropriately when Redis operations throw an error.
@redis_fallback(default_return=None)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
JohnJyong
approved these changes
Jul 10, 2025
crazywoola
approved these changes
Jul 10, 2025
5 tasks
Scorpion1221
added a commit
to yybht155/dify
that referenced
this pull request
Jul 16, 2025
* commit '390e4cc0bf203a979e13694ed99ec9fda6b42cc8': (143 commits) chore(version): bump to 1.6.0 (langgenius#22136) chore: fix schema editor can not hover item (langgenius#22155) fix: add the default value to the dark icon (langgenius#22149) feat: support ping method for MCP server (langgenius#22144) fix: mcp server card button display (langgenius#22141) feat: add support for dark icons in provider and tool entities (langgenius#22081) update worklow events logs. (langgenius#19871) chore: translate i18n files (langgenius#22132) feat: the frontend part of mcp (langgenius#22131) feat: add MCP support (langgenius#20716) Fix: Resolve issue with json_output (langgenius#22053) Chore: rm useless import and vars (langgenius#22108) feat: add redis fallback mechanism langgenius#21043 (langgenius#21044) optimize: batch embedding and qdrant write_consistency_factor parameter (langgenius#21776) chore: Update theme vars (langgenius#22113) feat(question-classifier): add drag-and-drop sorting for topics list (langgenius#22066) test: add comprehensive unit tests for encrypter module (langgenius#22102) fix: allow update plugin install settings (langgenius#22111) fix(Drawer): add overflow hidden to ensure copy button is always clickable (langgenius#21992) (langgenius#22103) Update clean_document_task.py (langgenius#22090) ... # Conflicts: # api/core/helper/code_executor/template_transformer.py # api/pyproject.toml # api/uv.lock
tutkun
pushed a commit
to tutkun/dify
that referenced
this pull request
Aug 15, 2025
Co-authored-by: tech <cto@sb> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Fixes #21043.Summary
This PR introduces a Redis fallback mechanism to improve the resilience of the Dify application when Redis operations fail. The implementation includes:
redis_fallbackdecorator: A decorator function that gracefully handles Redis operation exceptions and returns configurable default values when Redis is unavailableKey Changes:
redis_fallbackdecorator inext_redis.pyto handleRedisErrorexceptionsaccount_service.py:add_login_error_rate_limit()is_login_error_rate_limit()reset_login_error_rate_limit()add_forgot_password_error_rate_limit()This enhancement ensures that authentication and rate limiting features continue to function (with degraded capability) even when Redis is temporarily unavailable, preventing complete service disruption.
Fix #21043
Screenshots
Checklist
dev/reformat(backend) andcd web && npx lint-staged(frontend) to appease the lint gods