|
|
|
@ -205,8 +205,8 @@ public class RedissonRateLimiter extends RedissonObject implements RRateLimiter
|
|
|
|
|
+ "redis.call('decrby', valueName, ARGV[1]); "
|
|
|
|
|
+ "return nil; "
|
|
|
|
|
+ "end;",
|
|
|
|
|
Arrays.<Object>asList(getName(), getValueName(), getClientValueName()),
|
|
|
|
|
value, commandExecutor.getConnectionManager().getId());
|
|
|
|
|
Arrays.asList(getName(), getValueName(), getClientValueName()),
|
|
|
|
|
value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -220,7 +220,7 @@ public class RedissonRateLimiter extends RedissonObject implements RRateLimiter
|
|
|
|
|
"redis.call('hsetnx', KEYS[1], 'rate', ARGV[1]);"
|
|
|
|
|
+ "redis.call('hsetnx', KEYS[1], 'interval', ARGV[2]);"
|
|
|
|
|
+ "return redis.call('hsetnx', KEYS[1], 'type', ARGV[3]);",
|
|
|
|
|
Collections.<Object>singletonList(getName()), rate, unit.toMillis(rateInterval), type.ordinal());
|
|
|
|
|
Collections.singletonList(getName()), rate, unit.toMillis(rateInterval), type.ordinal());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final RedisCommand HGETALL = new RedisCommand("HGETALL", new MultiDecoder<RateLimiterConfig>() {
|
|
|
|
@ -263,7 +263,25 @@ public class RedissonRateLimiter extends RedissonObject implements RRateLimiter
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Long> availablePermitsAsync() {
|
|
|
|
|
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.GET_LONG, getValueName());
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_LONG,
|
|
|
|
|
"local rate = redis.call('hget', KEYS[1], 'rate');"
|
|
|
|
|
+ "local interval = redis.call('hget', KEYS[1], 'interval');"
|
|
|
|
|
+ "local type = redis.call('hget', KEYS[1], 'type');"
|
|
|
|
|
+ "assert(rate ~= false and interval ~= false and type ~= false, 'RateLimiter is not initialized')"
|
|
|
|
|
|
|
|
|
|
+ "local valueName = KEYS[2];"
|
|
|
|
|
+ "if type == '1' then "
|
|
|
|
|
+ "valueName = KEYS[3];"
|
|
|
|
|
+ "end;"
|
|
|
|
|
|
|
|
|
|
+ "local currentValue = redis.call('get', valueName); "
|
|
|
|
|
+ "if currentValue == false then "
|
|
|
|
|
+ "redis.call('set', valueName, rate, 'px', interval); "
|
|
|
|
|
+ "return rate; "
|
|
|
|
|
+ "else "
|
|
|
|
|
+ "return currentValue; "
|
|
|
|
|
+ "end;",
|
|
|
|
|
Arrays.asList(getName(), getValueName(), getClientValueName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|