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();
}
Aggregations