最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring - Rate limit bucket with Bucket4j and Redis not updated after limits are changed - Stack Overflow

programmeradmin2浏览0评论

I am using Spring with Java 17, Bucket4j and Redisson for rate limiting. What I've noticed that after changing the property which defines the limit or the interval of the rate limit the bucket is not updated. It gets the old bucket from redis with the old limits and proceeds accordingly.

I have tried the same with Hazelcast and Bucket4j and it works as expected. The new configurations are loaded and it handles the limit changes. I want to achieve the same behavior with redis as well.

Here is the code fragment which fetches the bucket from redis:

private final RedissonBasedProxyManager<String> redissonProxyManager;

...

private BlockingBucket getBucket(String name, long limit, long interval) {
    return redissonProxyManager.builder()
        .build(name, () -> Bucket.builder()
            .addLimit(Bandwidth.builder()
                .capacity(limit)
                .refillGreedy(limit, Duration.of(interval, ChronoUnit.SECONDS))
                .build())
            .build()
            .getConfiguration())
            .asBlocking();
}

I really want to avoid deleting the buckets manually every time I'm changing the rate limit.

发布评论

评论列表(0)

  1. 暂无评论