From d685fcc4184c41372c7fcf05363a485b287d89ab Mon Sep 17 00:00:00 2001 From: maddie-boisvert Date: Fri, 23 Dec 2022 10:10:41 -0600 Subject: [PATCH] Change return type of set permits to void Signed-off-by: maddie-boisvert --- .../redisson/RedissonPermitExpirableSemaphore.java | 14 ++++++-------- .../redisson/api/RPermitExpirableSemaphore.java | 5 ++--- .../api/RPermitExpirableSemaphoreAsync.java | 7 +++---- .../RedissonPermitExpirableSemaphoreTest.java | 12 ++++++------ 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java b/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java index 836080f1e..62756f0b9 100644 --- a/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java +++ b/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java @@ -700,13 +700,13 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen } @Override - public int setPermits(int permits) { - return get(setPermitsAsync(permits)); + public void setPermits(int permits) { + get(setPermitsAsync(permits)); } @Override - public RFuture setPermitsAsync(int permits) { - return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, + public RFuture setPermitsAsync(int permits) { + return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_VOID, "local available = redis.call('get', KEYS[1]); " + "if (available == false) then " + "redis.call('set', KEYS[1], ARGV[1]); " + @@ -718,10 +718,8 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen "if (maximum == ARGV[1]) then " + "return 0;" + "end;" + - "local delta = tonumber(ARGV[1]) - maximum; " + - "redis.call('incrby', KEYS[1], delta); " + - "redis.call('publish', KEYS[2], ARGV[1]); " + - "return delta;", + "redis.call('incrby', KEYS[1], tonumber(ARGV[1]) - maximum); " + + "redis.call('publish', KEYS[2], ARGV[1]);", Arrays.asList(getRawName(), getChannelName(), timeoutName), permits); } diff --git a/redisson/src/main/java/org/redisson/api/RPermitExpirableSemaphore.java b/redisson/src/main/java/org/redisson/api/RPermitExpirableSemaphore.java index 3cb94cfdc..6d7361140 100644 --- a/redisson/src/main/java/org/redisson/api/RPermitExpirableSemaphore.java +++ b/redisson/src/main/java/org/redisson/api/RPermitExpirableSemaphore.java @@ -131,14 +131,13 @@ public interface RPermitExpirableSemaphore extends RExpirable, RPermitExpirableS boolean trySetPermits(int permits); /** - * Sets the number of permits to the provided value and returns the number of permits added. + * Sets the number of permits to the provided value. * Calculates the delta between the given permits value and the * current number of permits, then increases the number of available permits by delta. * * @param permits - number of permits - * @return delta - number of permits that were added, will be negative if permits were removed */ - int setPermits(int permits); + void setPermits(int permits); /** * Increases or decreases the number of available permits by defined value. diff --git a/redisson/src/main/java/org/redisson/api/RPermitExpirableSemaphoreAsync.java b/redisson/src/main/java/org/redisson/api/RPermitExpirableSemaphoreAsync.java index fafea6b83..8e79cdfaf 100644 --- a/redisson/src/main/java/org/redisson/api/RPermitExpirableSemaphoreAsync.java +++ b/redisson/src/main/java/org/redisson/api/RPermitExpirableSemaphoreAsync.java @@ -128,14 +128,13 @@ public interface RPermitExpirableSemaphoreAsync extends RExpirableAsync { RFuture trySetPermitsAsync(int permits); /** - * Sets the number of permits to the provided value and returns the number of permits added. - * Calculates the delta between the given permits vaue and the + * Sets the number of permits to the provided value. + * Calculates the delta between the given permits value and the * current number of permits, then increases the number of available permits by delta. * * @param permits - number of permits - * @return delta - number of permits that were added, will be negative if permits were removed */ - RFuture setPermitsAsync(int permits); + RFuture setPermitsAsync(int permits); /** * Increases or decreases the number of available permits by defined value. diff --git a/redisson/src/test/java/org/redisson/RedissonPermitExpirableSemaphoreTest.java b/redisson/src/test/java/org/redisson/RedissonPermitExpirableSemaphoreTest.java index 18a59a989..bf1531670 100644 --- a/redisson/src/test/java/org/redisson/RedissonPermitExpirableSemaphoreTest.java +++ b/redisson/src/test/java/org/redisson/RedissonPermitExpirableSemaphoreTest.java @@ -183,7 +183,7 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest { @Test public void testSetPermits() throws InterruptedException { RPermitExpirableSemaphore s = redisson.getPermitExpirableSemaphore("test"); - assertThat(s.setPermits(10)).isEqualTo(10); + s.setPermits(10); assertThat(s.getPermits()).isEqualTo(10); assertThat(s.availablePermits()).isEqualTo(10); assertThat(s.claimedPermits()).isEqualTo(0); @@ -195,19 +195,19 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest { assertThat(s.claimedPermits()).isEqualTo(0); // attempts to set max permits succeeds - assertThat(s.setPermits(15)).isEqualTo(5); + s.setPermits(15); assertThat(s.getPermits()).isEqualTo(15); assertThat(s.availablePermits()).isEqualTo(15); assertThat(s.claimedPermits()).isEqualTo(0); // setting to existing value succeeds - assertThat(s.setPermits(15)).isEqualTo(0); + s.setPermits(15); assertThat(s.getPermits()).isEqualTo(15); assertThat(s.availablePermits()).isEqualTo(15); assertThat(s.claimedPermits()).isEqualTo(0); // decreasing max permits succeeds - assertThat(s.setPermits(5)).isEqualTo(-10); + s.setPermits(5); assertThat(s.getPermits()).isEqualTo(5); assertThat(s.availablePermits()).isEqualTo(5); assertThat(s.claimedPermits()).isEqualTo(0); @@ -225,14 +225,14 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest { assertThat(s.claimedPermits()).isEqualTo(3); // decreasing the max to the number of claimed permits is allowed - assertThat(s.setPermits(3)).isEqualTo(-2); + s.setPermits(3); assertThat(s.getPermits()).isEqualTo(3); assertThat(s.availablePermits()).isEqualTo(0); assertThat(s.claimedPermits()).isEqualTo(3); // decreasing the max to below the number of claimed permits is allowed // and results in a negative number of available permits - assertThat(s.setPermits(2)).isEqualTo(-1); + s.setPermits(2); assertThat(s.getPermits()).isEqualTo(2); assertThat(s.availablePermits()).isEqualTo(-1); assertThat(s.claimedPermits()).isEqualTo(3);