use of redis.clients.jedis.JedisPubSub in project jedis by xetorthio.
the class PublishSubscribeCommandsTest method unsubscribeWhenNotSusbscribed.
@Test(expected = JedisConnectionException.class)
public void unsubscribeWhenNotSusbscribed() throws InterruptedException {
JedisPubSub pubsub = new JedisPubSub() {
};
pubsub.unsubscribe();
}
use of redis.clients.jedis.JedisPubSub in project jedis by xetorthio.
the class PublishSubscribeCommandsTest method pubSubNumSub.
@Test
public void pubSubNumSub() {
final Map<String, String> expectedNumSub = new HashMap<String, String>();
expectedNumSub.put("testchannel2", "1");
expectedNumSub.put("testchannel1", "1");
jedis.subscribe(new JedisPubSub() {
private int count = 0;
@Override
public void onSubscribe(String channel, int subscribedChannels) {
count++;
if (count == 2) {
Jedis otherJedis = createJedis();
Map<String, String> numSub = otherJedis.pubsubNumSub("testchannel1", "testchannel2");
assertEquals(expectedNumSub, numSub);
unsubscribe();
}
}
}, "testchannel1", "testchannel2");
}
use of redis.clients.jedis.JedisPubSub in project jedis by xetorthio.
the class PublishSubscribeCommandsTest method subscribeLazily.
@Test
public void subscribeLazily() throws UnknownHostException, IOException, InterruptedException {
final JedisPubSub pubsub = new JedisPubSub() {
public void onMessage(String channel, String message) {
unsubscribe(channel);
}
public void onSubscribe(String channel, int subscribedChannels) {
publishOne(channel, "exit");
if (!channel.equals("bar")) {
this.subscribe("bar");
this.psubscribe("bar.*");
}
}
public void onPSubscribe(String pattern, int subscribedChannels) {
publishOne(pattern.replace("*", "123"), "exit");
}
public void onPMessage(String pattern, String channel, String message) {
punsubscribe(pattern);
}
};
jedis.subscribe(pubsub, "foo");
}
Aggregations