feat: 任务 7 会话状态迁移到 Redis

新增 src/core/session_store.py:
- SessionStore 抽象接口(get/set/delete/list_all/check_and_set_dedup)
- MemorySessionStore: 内存实现(单进程,带 TTL 和容量限制)
- RedisSessionStore: Redis 实现(多进程共享,SETNX 原子去重)
- create_session_store(): 优先 Redis,降级内存

RealtimeChatManager 集成:
- 初始化时创建 session_store(自动选择 Redis 或内存)
- create_session 同时写入 session_store
- end_session 同时从 session_store 删除
- get_active_sessions 合并内存和 session_store 的会话(跨进程可见)

支持多实例部署:
- 配置 REDIS_ENABLED=true + REDIS_HOST 即可启用
- 不配置 Redis 时行为完全不变(内存存储)
This commit is contained in:
2026-04-08 08:59:11 +08:00
parent 45badfee82
commit 54d4043805
3 changed files with 235 additions and 15 deletions

4
.env
View File

@@ -17,10 +17,8 @@ WEBSOCKET_PORT=8765
# Set to "True" for development to enable debug mode and auto-reloading.
# Set to "False" for production.
DEBUG_MODE=False
# Logging level for the application. Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_LEVEL=INFO
# 租户标识 — 多项目共用同一套代码时,用不同的 TENANT_ID 隔离数据
TENANT_ID=default
@@ -42,7 +40,7 @@ DATABASE_URL=sqlite:///./data/tsp_assistant.db
# LARGE LANGUAGE MODEL (LLM) CONFIGURATION
# ============================================================================
# The provider of the LLM. Supported: "qwen", "openai", "anthropic"
LLM_PROVIDER=qwen
LLM_PROVIDER=xiaomi
# The API key for your chosen LLM provider.
LLM_API_KEY=sk-Gce85QLROESeOWf3icd2mQnYHOrmMYojwVPQ0AubMjGQ5ZE2