|
|
@ -357,7 +357,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private RFuture<String> tryAcquireAsync(byte[] id, int permits, long timeoutDate) {
|
|
|
|
private RFuture<String> tryAcquireAsync(byte[] id, int permits, long timeoutDate) {
|
|
|
|
return commandExecutor.syncedEvalWriteAsync(getRawName(), ByteArrayCodec.INSTANCE, RedisCommands.EVAL_PERMIT_DATA,
|
|
|
|
return commandExecutor.syncedEval(getRawName(), ByteArrayCodec.INSTANCE, RedisCommands.EVAL_PERMIT_DATA,
|
|
|
|
"local expiredIds = redis.call('zrangebyscore', KEYS[2], 0, ARGV[4], 'limit', 0, ARGV[1]); " +
|
|
|
|
"local expiredIds = redis.call('zrangebyscore', KEYS[2], 0, ARGV[4], 'limit', 0, ARGV[1]); " +
|
|
|
|
"if #expiredIds > 0 then " +
|
|
|
|
"if #expiredIds > 0 then " +
|
|
|
|
"redis.call('zrem', KEYS[2], unpack(expiredIds)); " +
|
|
|
|
"redis.call('zrem', KEYS[2], unpack(expiredIds)); " +
|
|
|
@ -567,7 +567,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
byte[] id = ByteBufUtil.decodeHexDump(permitId);
|
|
|
|
byte[] id = ByteBufUtil.decodeHexDump(permitId);
|
|
|
|
return evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
return commandExecutor.syncedEvalWithRetry(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
"local expire = redis.call('zscore', KEYS[3], ARGV[1]);" +
|
|
|
|
"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 " +
|
|
|
@ -707,7 +707,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public RFuture<Void> setPermitsAsync(int permits) {
|
|
|
|
public RFuture<Void> setPermitsAsync(int permits) {
|
|
|
|
return evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_VOID,
|
|
|
|
return commandExecutor.syncedEvalWithRetry(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_VOID,
|
|
|
|
"local available = redis.call('get', KEYS[1]); " +
|
|
|
|
"local available = redis.call('get', KEYS[1]); " +
|
|
|
|
"if (available == false) then " +
|
|
|
|
"if (available == false) then " +
|
|
|
|
"redis.call('set', KEYS[1], ARGV[1]); " +
|
|
|
|
"redis.call('set', KEYS[1], ARGV[1]); " +
|
|
|
@ -726,7 +726,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public RFuture<Boolean> trySetPermitsAsync(int permits) {
|
|
|
|
public RFuture<Boolean> trySetPermitsAsync(int permits) {
|
|
|
|
return evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
return commandExecutor.syncedEvalWithRetry(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
"local value = redis.call('get', KEYS[1]); " +
|
|
|
|
"local value = redis.call('get', KEYS[1]); " +
|
|
|
|
"if (value == false) then "
|
|
|
|
"if (value == false) then "
|
|
|
|
+ "redis.call('set', KEYS[1], ARGV[1]); "
|
|
|
|
+ "redis.call('set', KEYS[1], ARGV[1]); "
|
|
|
@ -744,7 +744,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public RFuture<Void> addPermitsAsync(int permits) {
|
|
|
|
public RFuture<Void> addPermitsAsync(int permits) {
|
|
|
|
return evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_VOID,
|
|
|
|
return commandExecutor.syncedEvalWithRetry(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_VOID,
|
|
|
|
"local value = redis.call('get', KEYS[1]); " +
|
|
|
|
"local value = redis.call('get', KEYS[1]); " +
|
|
|
|
"if (value == false) then "
|
|
|
|
"if (value == false) then "
|
|
|
|
+ "value = 0;"
|
|
|
|
+ "value = 0;"
|
|
|
@ -760,7 +760,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
|
|
|
|
public RFuture<Boolean> updateLeaseTimeAsync(String permitId, long leaseTime, TimeUnit unit) {
|
|
|
|
public RFuture<Boolean> updateLeaseTimeAsync(String permitId, long leaseTime, TimeUnit unit) {
|
|
|
|
long timeoutDate = calcTimeout(leaseTime, unit);
|
|
|
|
long timeoutDate = calcTimeout(leaseTime, unit);
|
|
|
|
byte[] id = ByteBufUtil.decodeHexDump(permitId);
|
|
|
|
byte[] id = ByteBufUtil.decodeHexDump(permitId);
|
|
|
|
return evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
return commandExecutor.syncedEvalWithRetry(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
"local expiredIds = redis.call('zrangebyscore', KEYS[2], 0, ARGV[3], 'limit', 0, -1); " +
|
|
|
|
"local expiredIds = redis.call('zrangebyscore', KEYS[2], 0, ARGV[3], 'limit', 0, -1); " +
|
|
|
|
"if #expiredIds > 0 then " +
|
|
|
|
"if #expiredIds > 0 then " +
|
|
|
|
"redis.call('zrem', KEYS[2], unpack(expiredIds)); " +
|
|
|
|
"redis.call('zrem', KEYS[2], unpack(expiredIds)); " +
|
|
|
@ -785,8 +785,4 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
|
|
|
|
return get(updateLeaseTimeAsync(permitId, leaseTime, unit));
|
|
|
|
return get(updateLeaseTimeAsync(permitId, leaseTime, unit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private <T> RFuture<T> evalWriteAsync(String key, Codec codec, RedisCommand<T> evalCommandType, String script, List<Object> keys, Object... params) {
|
|
|
|
|
|
|
|
return commandExecutor.getServiceManager().execute(() -> commandExecutor.syncedEvalWriteAsync(key, codec, evalCommandType, script, keys, params));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|