From 188ca2f84e703e7a2f4149f9fc58289e3632cf85 Mon Sep 17 00:00:00 2001 From: lyrric Date: Thu, 10 Oct 2024 18:06:35 +0800 Subject: [PATCH] Improvement - Add check, The parameter timeToLive should be greater than or equal to rateInterval Signed-off-by: lyrric --- redisson/src/main/java/org/redisson/RedissonRateLimiter.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/redisson/src/main/java/org/redisson/RedissonRateLimiter.java b/redisson/src/main/java/org/redisson/RedissonRateLimiter.java index 6bf75927f..6cc8ca68d 100644 --- a/redisson/src/main/java/org/redisson/RedissonRateLimiter.java +++ b/redisson/src/main/java/org/redisson/RedissonRateLimiter.java @@ -277,6 +277,9 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit @Override public RFuture trySetRateAsync(RateType type, long rate, Duration rateInterval, Duration timeToLive) { + if (timeToLive.toMillis() < rateInterval.toMillis()) { + throw new IllegalArgumentException("The parameter timeToLive should be greater than or equal to rateInterval"); + } return commandExecutor.evalWriteNoRetryAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, "redis.call('hsetnx', KEYS[1], 'rate', ARGV[1]);" + "redis.call('hsetnx', KEYS[1], 'interval', ARGV[2]);"