use of redis.clients.jedis.BinaryJedisPubSub in project jedis by xetorthio.
the class PublishSubscribeCommandsTest method binarySubscribeLazily.
@Test
public void binarySubscribeLazily() throws UnknownHostException, IOException, InterruptedException {
final BinaryJedisPubSub pubsub = new BinaryJedisPubSub() {
public void onMessage(byte[] channel, byte[] message) {
unsubscribe(channel);
}
public void onSubscribe(byte[] channel, int subscribedChannels) {
publishOne(SafeEncoder.encode(channel), "exit");
if (!SafeEncoder.encode(channel).equals("bar")) {
this.subscribe(SafeEncoder.encode("bar"));
this.psubscribe(SafeEncoder.encode("bar.*"));
}
}
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
publishOne(SafeEncoder.encode(pattern).replace("*", "123"), "exit");
}
public void onPMessage(byte[] pattern, byte[] channel, byte[] message) {
punsubscribe(pattern);
}
};
jedis.subscribe(pubsub, SafeEncoder.encode("foo"));
}
Aggregations