rename methods, add to other interfaces, refactor

Signed-off-by: Abhishek Chandrasekaran <abchandrasekar@expediagroup.com>
pull/3003/head
Abhishek Chandrasekaran 5 years ago
parent d9b33d64f3
commit 07e693fd9f

@ -244,18 +244,18 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit
} }
@Override @Override
public boolean updateRate(RateType type, long rate, long rateInterval, RateIntervalUnit unit) { public boolean setRate(RateType type, long rate, long rateInterval, RateIntervalUnit unit) {
return get(updateRateAsync(type, rate, rateInterval, unit)); return get(setRateAsync(type, rate, rateInterval, unit));
} }
@Override @Override
public RFuture<Boolean> updateRateAsync(RateType type, long rate, long rateInterval, RateIntervalUnit unit) { public RFuture<Boolean> setRateAsync(RateType type, long rate, long rateInterval, RateIntervalUnit unit) {
return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"redis.call('hset', KEYS[1], 'rate', ARGV[1]);" "redis.call('hset', KEYS[1], 'rate', ARGV[1]);"
+ "redis.call('hset', KEYS[1], 'interval', ARGV[2]);" + "redis.call('hset', KEYS[1], 'interval', ARGV[2]);"
+ "redis.call('hset', KEYS[1], 'type', ARGV[3]);" + "redis.call('hset', KEYS[1], 'type', ARGV[3]);"
+ "return redis.call('del', ARGV[4], ARGV[5]);", + "return redis.call('del', KEYS[2], KEYS[3]);",
Collections.<Object>singletonList(getName()), rate, unit.toMillis(rateInterval), type.ordinal(), getValueName(), getPermitsName()); Arrays.asList(getName(), getValueName(), getPermitsName()), rate, unit.toMillis(rateInterval), type.ordinal());
} }
private static final RedisCommand HGETALL = new RedisCommand("HGETALL", new MultiDecoder<RateLimiterConfig>() { private static final RedisCommand HGETALL = new RedisCommand("HGETALL", new MultiDecoder<RateLimiterConfig>() {

@ -47,7 +47,7 @@ public interface RRateLimiter extends RRateLimiterAsync, RExpirable {
* @return {@code true} if rate was set and {@code false} * @return {@code true} if rate was set and {@code false}
* otherwise * otherwise
*/ */
boolean updateRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit); boolean setRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit);
/** /**
* Acquires a permit only if one is available at the * Acquires a permit only if one is available at the

@ -155,7 +155,7 @@ public interface RRateLimiterAsync extends RExpirableAsync {
* @return {@code true} if rate was set and {@code false} * @return {@code true} if rate was set and {@code false}
* otherwise * otherwise
*/ */
RFuture<Boolean> updateRateAsync(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit); RFuture<Boolean> setRateAsync(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit);
/** /**
* Returns current configuration of this RateLimiter object. * Returns current configuration of this RateLimiter object.

@ -39,6 +39,18 @@ public interface RRateLimiterReactive extends RExpirableReactive {
*/ */
Mono<Boolean> trySetRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit); Mono<Boolean> trySetRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit);
/**
* Updates RateLimiter's state and stores config to Redis server.
*
* @param mode - rate mode
* @param rate - rate
* @param rateInterval - rate time interval
* @param rateIntervalUnit - rate time interval unit
* @return {@code true} if rate was set and {@code false}
* otherwise
*/
Mono<Boolean> setRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit);
/** /**
* Acquires a permit only if one is available at the * Acquires a permit only if one is available at the
* time of invocation. * time of invocation.

@ -40,6 +40,18 @@ public interface RRateLimiterRx extends RExpirableRx {
*/ */
Single<Boolean> trySetRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit); Single<Boolean> trySetRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit);
/**
* Updates RateLimiter's state and stores config to Redis server.
*
* @param mode - rate mode
* @param rate - rate
* @param rateInterval - rate time interval
* @param rateIntervalUnit - rate time interval unit
* @return {@code true} if rate was set and {@code false}
* otherwise
*/
Single<Boolean> setRate(RateType mode, long rate, long rateInterval, RateIntervalUnit rateIntervalUnit);
/** /**
* Acquires a permit only if one is available at the * Acquires a permit only if one is available at the
* time of invocation. * time of invocation.

Loading…
Cancel
Save