@ -387,6 +387,12 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
"if (value ~= false and tonumber(value) >= tonumber(ARGV[1])) then " +
"redis.call('decrby', KEYS[1], ARGV[1]); " +
"redis.call('zadd', KEYS[2], ARGV[2], ARGV[3]); " +
"local ttl = redis.call('pttl', KEYS[1]); " +
"if ttl > 0 then " +
"redis.call('pexpire', KEYS[2], ttl); " +
"end; " +
"return ARGV[3]; " +
"local v = redis.call('zrange', KEYS[2], 0, 0, 'WITHSCORES'); " +
@ -55,7 +55,17 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest {
Thread.sleep(1100);
Assert.assertEquals(2, semaphore.availablePermits());
}
@Test
public void testExpiration() throws InterruptedException {
RPermitExpirableSemaphore semaphore = redisson.getPermitExpirableSemaphore("some-key");
semaphore.trySetPermits(1);
semaphore.expire(3, TimeUnit.SECONDS);
semaphore.tryAcquire(1, 1, TimeUnit.SECONDS);
Thread.sleep(4000);
assertThat(redisson.getKeys().count()).isZero();
public void testExpire() throws InterruptedException {
RPermitExpirableSemaphore s = redisson.getPermitExpirableSemaphore("test");