use of org.redisson.client.RedisPubSubConnection in project redisson by redisson.
the class RedisClientTest method testSubscribe.
@Test
public void testSubscribe() throws InterruptedException {
RedisClient c = new RedisClient(RedisRunner.getDefaultRedisServerBindAddressAndPort());
RedisPubSubConnection pubSubConnection = c.connectPubSub();
final CountDownLatch latch = new CountDownLatch(2);
pubSubConnection.addListener(new RedisPubSubListener<Object>() {
@Override
public boolean onStatus(PubSubType type, String channel) {
assertThat(type).isEqualTo(PubSubType.SUBSCRIBE);
assertThat(Arrays.asList("test1", "test2").contains(channel)).isTrue();
latch.countDown();
return true;
}
@Override
public void onMessage(String channel, Object message) {
}
@Override
public void onPatternMessage(String pattern, String channel, Object message) {
}
});
pubSubConnection.subscribe(StringCodec.INSTANCE, "test1", "test2");
latch.await(10, TimeUnit.SECONDS);
}
Aggregations