Search in sources :

Example 1 with ExpiredObjectListener

use of org.redisson.api.ExpiredObjectListener in project redisson by redisson.

the class RedissonBucketTest method testExpiredListener.

@Test
public void testExpiredListener() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisProcess instance = new RedisRunner().nosave().randomPort().randomDir().notifyKeyspaceEvents(KEYSPACE_EVENTS_OPTIONS.E, KEYSPACE_EVENTS_OPTIONS.x).run();
    Config config = new Config();
    config.useSingleServer().setAddress(instance.getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    RBucket<Integer> al = redisson.getBucket("test");
    al.set(1, 3, TimeUnit.SECONDS);
    CountDownLatch latch = new CountDownLatch(1);
    al.addListener(new ExpiredObjectListener() {

        @Override
        public void onExpired(String name) {
            latch.countDown();
        }
    });
    assertThat(latch.await(4, TimeUnit.SECONDS)).isTrue();
    redisson.shutdown();
    instance.stop();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) ExpiredObjectListener(org.redisson.api.ExpiredObjectListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1 RedisProcess (org.redisson.RedisRunner.RedisProcess)1 ExpiredObjectListener (org.redisson.api.ExpiredObjectListener)1 RedissonClient (org.redisson.api.RedissonClient)1 Config (org.redisson.config.Config)1