|
NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
|
令牌桶限流管理器 更多...
#include <rate_limiter.hpp>
Public 成员函数 | |
| bool | allow (const string &key, double rate=0.0, double burst=0.0) |
| 检查并消耗令牌 | |
| void | set_default_rate (double rate) |
| 设置默认的令牌补充速率 | |
| void | set_default_burst (double burst) |
| 设置默认的桶容量 | |
| size_t | size () const |
| 获取桶数量 | |
| void | cleanup_expired (seconds max_age=seconds{300}) |
| 清理过期的桶 | |
| bool neforce::http::token_bucket_limiter::allow | ( | const string & | key, |
| double | rate = 0.0, | ||
| double | burst = 0.0 ) |
检查并消耗令牌
| key | 客户端标识(如IP或IP+路由) |
| rate | 每秒补充令牌数(<=0 使用默认) |
| burst | 桶容量(<=0 使用默认) |
清理过期的桶
| max_age | 超过此时间未使用的桶将被移除 |