From ca3e45bc20e663d1be9cb4952c53599463cdd995 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Thu, 23 Sep 2021 19:11:28 +0300 Subject: [PATCH] refactoring --- .../src/main/java/org/redisson/RedissonRateLimiter.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/redisson/src/main/java/org/redisson/RedissonRateLimiter.java b/redisson/src/main/java/org/redisson/RedissonRateLimiter.java index fa58c0cc4..977a1dc77 100644 --- a/redisson/src/main/java/org/redisson/RedissonRateLimiter.java +++ b/redisson/src/main/java/org/redisson/RedissonRateLimiter.java @@ -15,6 +15,8 @@ */ package org.redisson; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import org.redisson.api.*; import org.redisson.client.codec.LongCodec; import org.redisson.client.codec.StringCodec; @@ -180,6 +182,10 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit } private RFuture tryAcquireAsync(RedisCommand command, Long value) { + ByteBuf buf = Unpooled.copyLong(ThreadLocalRandom.current().nextLong()); + byte[] random = buf.array(); + buf.release(); + return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, command, "local rate = redis.call('hget', KEYS[1], 'rate');" + "local interval = redis.call('hget', KEYS[1], 'interval');" @@ -229,7 +235,7 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit + "return nil; " + "end;", Arrays.asList(getRawName(), getValueName(), getClientValueName(), getPermitsName(), getClientPermitsName()), - value, System.currentTimeMillis(), ThreadLocalRandom.current().nextLong()); + value, System.currentTimeMillis(), random); } @Override