Search in sources :

Example 1 with SetObjectListener

use of org.redisson.api.listener.SetObjectListener in project redisson by redisson.

the class RedissonBucketTest method testSetListener.

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

        @Override
        public void onSet(String name) {
            latch.countDown();
        }
    });
    al.set(1);
    assertThat(latch.await(1, TimeUnit.SECONDS)).isTrue();
    redisson.shutdown();
    instance.stop();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) SetObjectListener(org.redisson.api.listener.SetObjectListener) 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 RedissonClient (org.redisson.api.RedissonClient)1 SetObjectListener (org.redisson.api.listener.SetObjectListener)1 Config (org.redisson.config.Config)1