diff --git a/backend/open_webui/utils/redis.py b/backend/open_webui/utils/redis.py index da6df2a7f..2040633a7 100644 --- a/backend/open_webui/utils/redis.py +++ b/backend/open_webui/utils/redis.py @@ -42,6 +42,38 @@ class SentinelRedisProxy: return orig_attr if self._async_mode: + if inspect.isasyncgenfunction(orig_attr): + + def _wrapped_iter(*args, **kwargs): + async def _iter(): + for i in range(REDIS_SENTINEL_MAX_RETRY_COUNT): + try: + method = getattr(self._master(), item) + async for value in method(*args, **kwargs): + yield value + return + except ( + redis.exceptions.ConnectionError, + redis.exceptions.ReadOnlyError, + ) as e: + if i < REDIS_SENTINEL_MAX_RETRY_COUNT - 1: + log.debug( + "Redis sentinel fail-over (%s). Retry %s/%s", + type(e).__name__, + i + 1, + REDIS_SENTINEL_MAX_RETRY_COUNT, + ) + continue + log.error( + "Redis operation failed after %s retries: %s", + REDIS_SENTINEL_MAX_RETRY_COUNT, + e, + ) + raise e from e + + return _iter() + + return _wrapped_iter async def _wrapped(*args, **kwargs): for i in range(REDIS_SENTINEL_MAX_RETRY_COUNT):