feat: add RPMCache interface and Redis implementation with Lua scripts
This commit is contained in:
17
backend/internal/service/rpm_cache.go
Normal file
17
backend/internal/service/rpm_cache.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user