|
|
|
@ -144,11 +144,14 @@ public class RedissonLock extends RedissonBaseLock {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RFuture<Boolean> tryAcquireOnceAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId) {
|
|
|
|
|
if (leaseTime != -1) {
|
|
|
|
|
return tryLockInnerAsync(waitTime, leaseTime, unit, threadId, RedisCommands.EVAL_NULL_BOOLEAN);
|
|
|
|
|
RFuture<Boolean> ttlRemainingFuture;
|
|
|
|
|
if (-1 != leaseTime) {
|
|
|
|
|
ttlRemainingFuture = tryLockInnerAsync(waitTime, leaseTime, unit, threadId, RedisCommands.EVAL_NULL_BOOLEAN);
|
|
|
|
|
} else {
|
|
|
|
|
ttlRemainingFuture = tryLockInnerAsync(waitTime, internalLockLeaseTime,
|
|
|
|
|
TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_NULL_BOOLEAN);
|
|
|
|
|
}
|
|
|
|
|
RFuture<Boolean> ttlRemainingFuture = tryLockInnerAsync(waitTime, internalLockLeaseTime,
|
|
|
|
|
TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_NULL_BOOLEAN);
|
|
|
|
|
|
|
|
|
|
ttlRemainingFuture.onComplete((ttlRemaining, e) -> {
|
|
|
|
|
if (e != null) {
|
|
|
|
|
return;
|
|
|
|
@ -156,6 +159,7 @@ public class RedissonLock extends RedissonBaseLock {
|
|
|
|
|
|
|
|
|
|
// lock acquired
|
|
|
|
|
if (ttlRemaining) {
|
|
|
|
|
internalLockLeaseTime = -1 == leaseTime ? internalLockLeaseTime : unit.toMillis(leaseTime);
|
|
|
|
|
scheduleExpirationRenewal(threadId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -163,11 +167,13 @@ public class RedissonLock extends RedissonBaseLock {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <T> RFuture<Long> tryAcquireAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId) {
|
|
|
|
|
RFuture<Long> ttlRemainingFuture;
|
|
|
|
|
if (leaseTime != -1) {
|
|
|
|
|
return tryLockInnerAsync(waitTime, leaseTime, unit, threadId, RedisCommands.EVAL_LONG);
|
|
|
|
|
ttlRemainingFuture = tryLockInnerAsync(waitTime, leaseTime, unit, threadId, RedisCommands.EVAL_LONG);
|
|
|
|
|
} else {
|
|
|
|
|
ttlRemainingFuture = tryLockInnerAsync(waitTime, internalLockLeaseTime,
|
|
|
|
|
TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_LONG);
|
|
|
|
|
}
|
|
|
|
|
RFuture<Long> ttlRemainingFuture = tryLockInnerAsync(waitTime, internalLockLeaseTime,
|
|
|
|
|
TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_LONG);
|
|
|
|
|
ttlRemainingFuture.onComplete((ttlRemaining, e) -> {
|
|
|
|
|
if (e != null) {
|
|
|
|
|
return;
|
|
|
|
@ -175,6 +181,7 @@ public class RedissonLock extends RedissonBaseLock {
|
|
|
|
|
|
|
|
|
|
// lock acquired
|
|
|
|
|
if (ttlRemaining == null) {
|
|
|
|
|
internalLockLeaseTime = -1 == leaseTime ? internalLockLeaseTime : unit.toMillis(leaseTime);
|
|
|
|
|
scheduleExpirationRenewal(threadId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -187,8 +194,6 @@ public class RedissonLock extends RedissonBaseLock {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<T> RFuture<T> tryLockInnerAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId, RedisStrictCommand<T> command) {
|
|
|
|
|
internalLockLeaseTime = unit.toMillis(leaseTime);
|
|
|
|
|
|
|
|
|
|
return evalWriteAsync(getName(), LongCodec.INSTANCE, command,
|
|
|
|
|
"if (redis.call('exists', KEYS[1]) == 0) then " +
|
|
|
|
|
"redis.call('hincrby', KEYS[1], ARGV[2], 1); " +
|
|
|
|
@ -201,7 +206,7 @@ public class RedissonLock extends RedissonBaseLock {
|
|
|
|
|
"return nil; " +
|
|
|
|
|
"end; " +
|
|
|
|
|
"return redis.call('pttl', KEYS[1]);",
|
|
|
|
|
Collections.singletonList(getName()), internalLockLeaseTime, getLockName(threadId));
|
|
|
|
|
Collections.singletonList(getName()), unit.toMillis(leaseTime), getLockName(threadId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|