use of org.redisson.client.protocol.pubsub.PubSubType in project redisson by redisson.
the class MasterSlaveConnectionManager method punsubscribe.
public Codec punsubscribe(final String channelName, final AsyncSemaphore lock) {
final PubSubConnectionEntry entry = name2PubSubConnection.remove(channelName);
if (entry == null) {
lock.release();
return null;
}
Codec entryCodec = entry.getConnection().getPatternChannels().get(channelName);
entry.punsubscribe(channelName, new BaseRedisPubSubListener() {
@Override
public boolean onStatus(PubSubType type, String channel) {
if (type == PubSubType.PUNSUBSCRIBE && channel.equals(channelName)) {
if (entry.release() == 1) {
freePubSubConnections.add(entry);
}
lock.release();
return true;
}
return false;
}
});
return entryCodec;
}
use of org.redisson.client.protocol.pubsub.PubSubType in project redisson by redisson.
the class PubSubConnectionEntry method punsubscribe.
public void punsubscribe(final String channel, final RedisPubSubListener<?> listener) {
conn.addListener(new BaseRedisPubSubListener() {
@Override
public boolean onStatus(PubSubType type, String ch) {
if (type == PubSubType.PUNSUBSCRIBE && channel.equals(ch)) {
conn.removeListener(this);
removeListeners(channel);
if (listener != null) {
listener.onStatus(type, channel);
}
return true;
}
return false;
}
});
conn.punsubscribe(channel);
}
use of org.redisson.client.protocol.pubsub.PubSubType 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