![](/img/trans.png)
[英]What is the purpose of renaming this key in a redis sliding window rate limiter implementation?
[英]Java based Rate limiter with Redis + RollingLimit + backoff
我正在尋找一種基於 Java 的速率限制器方法,類似於此處的 javascript 版本。 我本質上是在尋找類似的設置,在該設置中我使用與時間戳相關的滾動限制策略,並且在存儲桶已滿的情況下獲得退避值。
const IORedis = require('ioredis')
const RollingLimit = require('redis-token-bucket-ratelimiter');
.
.
.
.
const limiter = new RollingLimit({interval: reqInterval, limit: reqLimit,redis: redisClient, prefix: reqNamespace});
try {
limit = await limiter.use(reqKey, reqAmount);
/*
Where limit is of format
type RollingLimiterResult = {
limit: number, // the limit passed into `RollingLimiterOptions` on this invocation
remaining: number, // the number of tokens left in the bucket. Can be negative with `force`
rejected: boolean, // `true` if the request was rejected, `false` otherwise
retryDelta: number, // if rejected, milliseconds to wait before making the next request
forced: boolean, // if `true`, `force` was on (see `RollingLimiterOptions`)
};
*/
} catch (e) {
console.error(getMessage(e, reqNamespace, reqKey, reqAmount, reqInterval, reqLimit));
}
到目前為止,我查看了下面的各種方法,但它們沒有返回我特別尋找的退避時間。
PS:任何建議都會有所幫助。 提前感謝您的投入。
你說 Bucket4j 不返回退避是什么意思? 在此示例https://bucket4j.com/8.1.1/toc.html#limiting-the-rate-of-access-to-rest-api中描述了如何設置 X-Rate-Limit-Retry-After- HTTP 響應的秒數。 庫還提供豐富的 API https://bucket4j.com/8.1.1/toc.html#verbose-api允許獲取更多診斷信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.