Лаба 2: PostgreSQL-хранилище и Redis-сессии (оценка 4)

FastAPI + asyncpg + Redis/argon2id. Пользователи/чаты/участники/сообщения
в Postgres с версионируемой миграцией и keyset-пагинацией. Basic-вход,
Bearer-сессии в Redis с TTL и AOF-персистентностью. make check/test/
test-persistence/validate зелёные; evidence по EXPLAIN ANALYZE, короткому
TTL и падению Redis приложены в REPORT.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 00:23:26 +03:00
co-authored by Claude Sonnet 5
parent 65003b6119
commit d12159a8cc
13 changed files with 886 additions and 15 deletions
+29
View File
@@ -0,0 +1,29 @@
"""Canonical error envelope: {"error": {"code", "message", "request_id"}}."""
class ApiError(Exception):
def __init__(self, status: int, code: str, message: str):
self.status = status
self.code = code
self.message = message
super().__init__(message)
def bad_request(message: str) -> ApiError:
return ApiError(400, "invalid_request", message)
def unauthorized(message: str = "authentication required") -> ApiError:
return ApiError(401, "unauthorized", message)
def not_found(message: str = "not found") -> ApiError:
return ApiError(404, "not_found", message)
def conflict(message: str) -> ApiError:
return ApiError(409, "conflict", message)
def unavailable(message: str = "dependency unavailable") -> ApiError:
return ApiError(503, "unavailable", message)