From 3c3e49e98505ecfec1c33b91d947e931107e827c Mon Sep 17 00:00:00 2001 From: Erhan Ceran Date: Tue, 25 Jan 2022 15:15:45 +0300 Subject: [PATCH] Check expiration before release in RedissonPermitExpirableSemaphore Signed-off-by: Erhan Ceran --- .../RedissonPermitExpirableSemaphore.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java b/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java index 19cb26f6c..a6cc7a964 100644 --- a/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java +++ b/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java @@ -552,22 +552,25 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen public boolean tryRelease(String permitId) { return get(tryReleaseAsync(permitId)); } - - @Override + public RFuture tryReleaseAsync(String permitId) { if (permitId == null) { throw new IllegalArgumentException("permitId can't be null"); } return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, - "local removed = redis.call('zrem', KEYS[3], ARGV[1]);" + - "if tonumber(removed) ~= 1 then " + - "return 0;" + - "end;" + - "local value = redis.call('incrby', KEYS[1], ARGV[2]); " + - "redis.call('publish', KEYS[2], value); " + - "return 1;", - Arrays.asList(getRawName(), getChannelName(), timeoutName), permitId, 1); + "local expire = redis.call('zscore', KEYS[3], ARGV[1]);" + + "local removed = redis.call('zrem', KEYS[3], ARGV[1]);" + + "if tonumber(removed) ~= 1 then " + + "return 0;" + + "end;" + + "local value = redis.call('incrby', KEYS[1], ARGV[2]); " + + "redis.call('publish', KEYS[2], value); " + + "if tonumber(expire) <= tonumber(ARGV[3]) then " + + "return 0;" + + "end;" + + "return 1;", + Arrays.asList(getRawName(), getChannelName(), timeoutName), permitId, 1, System.currentTimeMillis()); } @Override