feat: add RPMCache interface and Redis implementation with Lua scripts

This commit is contained in:
QTom
2026-02-28 01:14:55 +08:00
parent 0bb3e4a98c
commit 777be05348
2 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
package service
import "context"
// RPMCache RPM 计数器缓存接口
// 用于 Anthropic OAuth/SetupToken 账号的每分钟请求数限制
type RPMCache interface {
// IncrementRPM 原子递增并返回当前分钟的计数
// 使用 Redis 服务器时间确定 minute key避免多实例时钟偏差
IncrementRPM(ctx context.Context, accountID int64) (count int, err error)
// GetRPM 获取当前分钟的 RPM 计数
GetRPM(ctx context.Context, accountID int64) (count int, err error)
// GetRPMBatch 批量获取多个账号的 RPM 计数(使用 Pipeline
GetRPMBatch(ctx context.Context, accountIDs []int64) (map[int64]int, error)
}