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
@@ -35,7 +35,8 @@ kdf_concurrency = 4
[cache]
# Адрес, порт и пароль Valkey приходят из .env (мосты к VALKEY_*) и из
# environment compose; здесь их не указывать.
# секунды на соединение и ответ Valkey; дольше — запрос идёт в PostgreSQL
# секунды на всю команду Valkey (ожидание пула, соединение, ответ);
# дольше — запрос идёт в PostgreSQL
timeout_seconds = 0.2
# секунды, на которые кэш пропускается после отказа Valkey
retry_after_seconds = 5