[PR #15718] [MERGED] feat: add Redis Sentinel failover support for high availability #23926

Closed
opened 2026-04-20 05:07:25 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/15718
Author: @sihyeonn
Created: 7/15/2025
Status: Merged
Merged: 7/16/2025
Merged by: @tjbck

Base: devHead: feat/sh-support-failover


📝 Commits (6)

  • 423d092 feat: add Redis Sentinel failover support for high availability
  • 728c39e chore: add tests with pytest-asyncio
  • 5fe0c83 chore: update lock file for pytest-asyncio
  • 1b7ac7c chore: format, lint
  • 65882c3 refactor: change MAX_RETRY_COUNT as env
  • 9067eac chore: add log for redis.exceptions

📊 Changes

5 files changed (+3191 additions, -2532 deletions)

View changed files

📝 backend/open_webui/env.py (+9 -0)
backend/open_webui/test/util/test_redis.py (+793 -0)
📝 backend/open_webui/utils/redis.py (+100 -4)
📝 pyproject.toml (+5 -0)
📝 uv.lock (+2284 -2528)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests to validate the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

  • Added comprehensive Redis Sentinel support with automatic failover capabilities to ensure high availability and fault tolerance in Redis deployments. Implemented SentinelRedisProxy class with retry logic to handle master failover scenarios seamlessly.

Added

  • SentinelRedisProxy class for Redis Sentinel integration with automatic failover
  • Retry mechanism with configurable MAX_RETRY_COUNT for connection resilience
  • Support for both async and sync Redis operations with Sentinel
  • Automatic master discovery and failover handling
  • Support for Redis authentication in Sentinel deployments
  • Add tests
    • Coverage:
      • URL Parsing: Validates Redis service URL parsing with various configurations
      • Failover Scenarios: Tests retry mechanism during master failover
      • Connection Errors: Handles ConnectionError and ReadOnlyError exceptions
      • Async/Sync Support: Validates both async and sync operation modes with correct mock paths
      • Factory Methods: Ensures proper handling of Redis pipeline an

Changed

  • Enhanced get_redis_connection() to support Sentinel-based connections
  • Improved Redis connection handling with failover capabilities
  • Add pytest-asyncio on dev dependency group

Fixed

  • Redis connection failures during master node outages
  • Service interruption during Redis master failover scenarios
  • Connection errors when Redis master becomes unavailable

Security

  • Enhanced Redis connection security with proper authentication handling in Sentinel mode
  • Improved error handling to prevent connection credential exposure

Breaking Changes

  • None - fully backward compatible with existing Redis configurations

Additional Information

  • High Availability: This implementation provides automatic failover when Redis master nodes become unavailable
  • Retry Logic: Implements intelligent retry mechanism (2 attempts by default) for handling transient connection issues
  • Dual Mode Support: Works with both async and sync Redis operations
  • Sentinel Discovery: Automatically discovers and connects to the current Redis master through Sentinel
  • Error Handling: Gracefully handles ConnectionError and ReadOnlyError exceptions with failover

Screenshots or Videos

  • Not applicable for backend Redis infrastructure enhancement

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/15718 **Author:** [@sihyeonn](https://github.com/sihyeonn) **Created:** 7/15/2025 **Status:** ✅ Merged **Merged:** 7/16/2025 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `feat/sh-support-failover` --- ### 📝 Commits (6) - [`423d092`](https://github.com/open-webui/open-webui/commit/423d0923d9368c2677d498082779882681555758) feat: add Redis Sentinel failover support for high availability - [`728c39e`](https://github.com/open-webui/open-webui/commit/728c39eed7c45818e5d5ce2b02e35a55733b6a4b) chore: add tests with pytest-asyncio - [`5fe0c83`](https://github.com/open-webui/open-webui/commit/5fe0c835b1bf5bb4d624d922864d9e6772eb0474) chore: update lock file for pytest-asyncio - [`1b7ac7c`](https://github.com/open-webui/open-webui/commit/1b7ac7c739f8e5e1fee56171647f9b2fb0baed71) chore: format, lint - [`65882c3`](https://github.com/open-webui/open-webui/commit/65882c30cbc9cacbca511649b70e54c919c2aeda) refactor: change MAX_RETRY_COUNT as env - [`9067eac`](https://github.com/open-webui/open-webui/commit/9067eac4ca14c5a75203ee54068598b8ec02b3a8) chore: add log for redis.exceptions ### 📊 Changes **5 files changed** (+3191 additions, -2532 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/env.py` (+9 -0) ➕ `backend/open_webui/test/util/test_redis.py` (+793 -0) 📝 `backend/open_webui/utils/redis.py` (+100 -4) 📝 `pyproject.toml` (+5 -0) 📝 `uv.lock` (+2284 -2528) </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [x] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Have you written and run sufficient tests to validate the changes? - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Description - Added comprehensive Redis Sentinel support with automatic failover capabilities to ensure high availability and fault tolerance in Redis deployments. Implemented `SentinelRedisProxy` class with retry logic to handle master failover scenarios seamlessly. ### Added - `SentinelRedisProxy` class for Redis Sentinel integration with automatic failover - Retry mechanism with configurable `MAX_RETRY_COUNT` for connection resilience - Support for both async and sync Redis operations with Sentinel - Automatic master discovery and failover handling - Support for Redis authentication in Sentinel deployments - Add tests - Coverage: - **URL Parsing**: Validates Redis service URL parsing with various configurations - **Failover Scenarios**: Tests retry mechanism during master failover - **Connection Errors**: Handles `ConnectionError` and `ReadOnlyError` exceptions - **Async/Sync Support**: Validates both async and sync operation modes with correct mock paths - **Factory Methods**: Ensures proper handling of Redis pipeline an ### Changed - Enhanced `get_redis_connection()` to support Sentinel-based connections - Improved Redis connection handling with failover capabilities - Add pytest-asyncio on dev dependency group ### Fixed - Redis connection failures during master node outages - Service interruption during Redis master failover scenarios - Connection errors when Redis master becomes unavailable ### Security - Enhanced Redis connection security with proper authentication handling in Sentinel mode - Improved error handling to prevent connection credential exposure ### Breaking Changes - None - fully backward compatible with existing Redis configurations --- ### Additional Information - **High Availability**: This implementation provides automatic failover when Redis master nodes become unavailable - **Retry Logic**: Implements intelligent retry mechanism (2 attempts by default) for handling transient connection issues - **Dual Mode Support**: Works with both async and sync Redis operations - **Sentinel Discovery**: Automatically discovers and connects to the current Redis master through Sentinel - **Error Handling**: Gracefully handles `ConnectionError` and `ReadOnlyError` exceptions with failover ### Screenshots or Videos - Not applicable for backend Redis infrastructure enhancement ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 05:07:25 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#23926