diff --git a/redisson/src/main/java/org/redisson/RedissonReadLock.java b/redisson/src/main/java/org/redisson/RedissonReadLock.java index d5a28cc81..173d6bd53 100644 --- a/redisson/src/main/java/org/redisson/RedissonReadLock.java +++ b/redisson/src/main/java/org/redisson/RedissonReadLock.java @@ -94,7 +94,7 @@ public class RedissonReadLock extends RedissonLock implements RLock { "if (mode == false) then " + "redis.call(ARGV[3], KEYS[2], ARGV[1]); " + "redis.call('set', KEYS[5], 1, 'px', ARGV[4]); " + - "return 1; " + + "return nil; " + "end; " + "local lockExists = redis.call('hexists', KEYS[1], ARGV[2]); " + "if (lockExists == 0) then " + diff --git a/redisson/src/main/java/org/redisson/RedissonWriteLock.java b/redisson/src/main/java/org/redisson/RedissonWriteLock.java index b7cb56b62..5bf6bf408 100644 --- a/redisson/src/main/java/org/redisson/RedissonWriteLock.java +++ b/redisson/src/main/java/org/redisson/RedissonWriteLock.java @@ -87,7 +87,7 @@ public class RedissonWriteLock extends RedissonLock implements RLock { "if (mode == false) then " + "redis.call(ARGV[4], KEYS[2], ARGV[1]); " + "redis.call('set', KEYS[3], 1, 'px', ARGV[5]); " + - "return 1; " + + "return nil; " + "end;" + "if (mode == 'write') then " + "local lockExists = redis.call('hexists', KEYS[1], ARGV[3]); " + diff --git a/redisson/src/test/java/org/redisson/RedissonReadWriteLockTest.java b/redisson/src/test/java/org/redisson/RedissonReadWriteLockTest.java index 4eb98ce4c..808c58102 100644 --- a/redisson/src/test/java/org/redisson/RedissonReadWriteLockTest.java +++ b/redisson/src/test/java/org/redisson/RedissonReadWriteLockTest.java @@ -16,8 +16,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.*; import static org.awaitility.Awaitility.await; public class RedissonReadWriteLockTest extends BaseConcurrentTest { @@ -439,6 +438,7 @@ public class RedissonReadWriteLockTest extends BaseConcurrentTest { for (int i = 0; i < 5; i++) { assertThat(rwlock.readLock().remainTimeToLive()).isGreaterThan(19000); + assertThat(rwlock.writeLock().remainTimeToLive()).isGreaterThan(19000); TimeUnit.SECONDS.sleep(5); } @@ -493,10 +493,11 @@ public class RedissonReadWriteLockTest extends BaseConcurrentTest { t.start(); t.join(); - lock.writeLock().unlock(); + assertThatThrownBy(() -> { + lock.writeLock().unlock(); + }).isInstanceOf(IllegalMonitorStateException.class); } - @Test public void testAutoExpire() throws InterruptedException { testSingleInstanceConcurrency(1, r -> {