Documentation
¶
Overview ¶
Package ratelimit 提供 Redis 令牌桶分布式限流: 多实例共享配额,原子 Lua 脚本保证正确性。 场景:接口限流(跨实例)、短信发送频率、防刷。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter 分布式限流器。
func NewLimiter ¶
NewLimiter 创建限流器。prefix 为 key 前缀(如 "rl:api"),可为空。
func (*Limiter) Allow ¶
Allow 请求 1 个令牌:放行返回 true;超额返回 false;错误返回 error。 rate 为每秒补充令牌数,burst 为桶容量(允许突发)。
Click to show internal directories.
Click to hide internal directories.