Files
sub2api/openspec/changes/update-rate-limit-ttl-atomic/tasks.md
yangjianbo 18b8bd43ad fix(限流): 原子化 Redis 限流并支持故障策略
使用 Lua 脚本原子设置计数与过期,修复 TTL 缺失\n支持 fail-open/fail-close 并对优惠码验证启用 fail-close\n新增单元与集成测试覆盖关键分支\n\n测试:go test ./...
2026-01-11 22:21:05 +08:00

7 lines
527 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 1. Implementation
- [x] 1.1 在限流中间件中引入 Lua 脚本原子化计数与过期设置(使用 PEXPIRE 毫秒窗口)
- [x] 1.2 脚本内检测 `TTL == -1` 时补设过期,修复历史脏 key
- [x] 1.3 引入 `RateLimitOptions``LimitWithOptions``Limit` 保持默认 fail-open
- [x] 1.4 为 `/auth/validate-promo-code` 配置 fail-close 策略
- [x] 1.5 添加测试覆盖首次请求、已有 TTL、TTL 缺失、非整数毫秒窗口与故障策略(使用 Redis 集成测试/testcontainers 方案)