Refactor Phase 2: Split stories.py into Schema/Service/Controller, add missing endpoints, fix async bug

This commit is contained in:
zhangtuo
2026-02-10 17:14:54 +08:00
parent c351d16d3e
commit 9cdff18336
13 changed files with 881 additions and 612 deletions

View File

@@ -52,6 +52,9 @@ class Settings(BaseSettings):
# Celery (Redis)
celery_broker_url: str = Field("redis://localhost:6379/0")
celery_result_backend: str = Field("redis://localhost:6379/0")
# Generic Redis
redis_url: str = Field("redis://localhost:6379/0", description="Redis connection URL")
# Admin console
enable_admin_console: bool = False

25
backend/app/core/redis.py Normal file
View File

@@ -0,0 +1,25 @@
"""Redis client module."""
from typing import AsyncGenerator
from redis.asyncio import Redis, from_url
from app.core.config import settings
_redis_pool: Redis | None = None
async def get_redis() -> Redis:
"""Get global Redis client instance."""
global _redis_pool
if _redis_pool is None:
_redis_pool = from_url(settings.redis_url, encoding="utf-8", decode_responses=True)
return _redis_pool
async def close_redis():
"""Close Redis connection."""
global _redis_pool
if _redis_pool:
await _redis_pool.close()
_redis_pool = None