Check expiration before release in RedissonPermitExpirableSemaphore

Signed-off-by: Erhan Ceran <erhanceran@yahoo.com>
pull/4091/head
Erhan Ceran
parent e7cc8fd81b
commit 3c3e49e985

@ -553,21 +553,24 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
return get(tryReleaseAsync(permitId)); return get(tryReleaseAsync(permitId));
} }
@Override
public RFuture<Boolean> tryReleaseAsync(String permitId) { public RFuture<Boolean> tryReleaseAsync(String permitId) {
if (permitId == null) { if (permitId == null) {
throw new IllegalArgumentException("permitId can't be null"); throw new IllegalArgumentException("permitId can't be null");
} }
return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"local expire = redis.call('zscore', KEYS[3], ARGV[1]);" +
"local removed = redis.call('zrem', KEYS[3], ARGV[1]);" + "local removed = redis.call('zrem', KEYS[3], ARGV[1]);" +
"if tonumber(removed) ~= 1 then " + "if tonumber(removed) ~= 1 then " +
"return 0;" + "return 0;" +
"end;" + "end;" +
"local value = redis.call('incrby', KEYS[1], ARGV[2]); " + "local value = redis.call('incrby', KEYS[1], ARGV[2]); " +
"redis.call('publish', KEYS[2], value); " + "redis.call('publish', KEYS[2], value); " +
"if tonumber(expire) <= tonumber(ARGV[3]) then " +
"return 0;" +
"end;" +
"return 1;", "return 1;",
Arrays.<Object>asList(getRawName(), getChannelName(), timeoutName), permitId, 1); Arrays.<Object>asList(getRawName(), getChannelName(), timeoutName), permitId, 1, System.currentTimeMillis());
} }
@Override @Override

Loading…
Cancel
Save