Реализованы сервисы ВМ2 - проверка сообщений и синхронизация с Б24 (деплой еще без перевода в боевой режим)

This commit is contained in:
mi
2026-08-13 18:52:42 +03:00
parent 5100ba9fc3
commit 99605b1c77
144 changed files with 15295 additions and 1120 deletions
@@ -0,0 +1,35 @@
from __future__ import annotations
import json
from typing import Any
from redis.asyncio import Redis
from redis.exceptions import RedisError
class RedisHotCache:
"""Best-effort accelerator; callers must always retain a PostgreSQL fallback."""
def __init__(self, client: Redis | None) -> None:
self.client = client
async def get(self, key: str) -> dict[str, Any] | None:
if not self.client:
return None
try:
value = await self.client.get(f"han:safety:{key}")
return json.loads(value) if value else None
except (RedisError, ValueError, TypeError):
return None
async def put(self, key: str, value: dict[str, Any], ttl: int) -> None:
if not self.client:
return
try:
await self.client.set(
f"han:safety:{key}",
json.dumps(value, separators=(",", ":"), sort_keys=True),
ex=ttl,
)
except RedisError:
return