Проект разделен на два репозитория

This commit is contained in:
mi
2026-08-14 15:42:45 +03:00
parent e06a77ee1d
commit bbef7a30c9
521 changed files with 2597 additions and 2302 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