fix: retry Valkey once on a dropped connection

The client passed the sync redis.retry.Retry to async connections, so no
retry could ever run. Use redis.asyncio.retry.Retry with one immediate
retry on ConnectionError only: after a Valkey restart the stale pooled
connection is reopened instead of switching the cache off for 5 s.
Timeouts are not retried, and asyncio.timeout bounds each cache command
(pool wait, connect, retry, reply) by [cache] timeout_seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 21:41:15 +03:00
co-authored by Claude Opus 5.5
parent 25a60d36cd
commit d7c9a5972b
7 changed files with 99 additions and 41 deletions
+2 -1
View File
@@ -105,7 +105,8 @@ class Cache(BaseModel):
port: int = Field(default=6379, ge=1, le=65535)
password: SecretStr = SecretStr("")
# секунды на соединение и ответ; дольше — запрос идёт в PostgreSQL
# секунды на всю команду кэша: ожидание пула, соединение, повтор и
# ответ; дольше — запрос идёт в PostgreSQL
timeout_seconds: float = Field(default=0.2, gt=0)
# секунды, на которые кэш пропускается после отказа Valkey
retry_after_seconds: float = Field(default=5, gt=0)