You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

Why

当前系统使用 SQLite 作为唯一存储后端,无法满足行情数据高频读写的性能需求。每次刷新行情数据都需要直接读写磁盘文件,导致响应延迟高、并发能力受限。需要引入更高效的存储方案以提升系统吞吐量和用户体验。

What Changes

  • 引入 Redis 作为热数据缓存层,行情数据优先从 Redis 读取TTL 30 天)
  • 引入 MySQL 作为持久化存储层,替代 SQLite 承担主要持久化职责
  • 保留 SQLite 作为最终兜底方案,当 Redis 和 MySQL 均不可用时启用
  • 新增数据访问层:实现 Redis → MySQL → SQLite 的三级降级读取策略
  • 刷新接口改造:数据同步写入 Redis 和 MySQL保证双写一致性
  • 启动流程改造:初始化 Redis/MySQL/SQLite 连接,检测可用性

Capabilities

New Capabilities

  • redis-cache-layer: Redis 缓存读写能力包括热数据缓存、TTL 管理、缓存失效策略
  • mysql-persistence: MySQL 持久化存储能力,替代 SQLite 承担主要持久化职责
  • storage-fallback: 三级降级策略Redis → MySQL → SQLite保证系统可用性
  • dual-write-consistency: 刷新接口双写能力,保证 Redis 和 MySQL 数据一致性

Modified Capabilities

(无既有 spec 需要修改)

Impact

  • 代码: app/database.pyapp/models.pyapp/api/data.pyapp/services/collector.pyapp/main.py
  • 依赖: 新增 redispymysql(或 aiomysqlPython 包
  • 配置: app/config.py 新增 Redis/MySQL 连接配置
  • 部署: docker-compose.yml 新增 Redis 和 MySQL 服务
  • 数据库: 新增 MySQL 数据库初始化脚本,保留 SQLite 作为兜底