@Override
public void connect(Properties props, CacheProviderHolder holder) {
long ct = System.currentTimeMillis();
this.holder = holder;
this.publish(Command.join());
Thread subscribeThread = new Thread(()-> {
while(!client.isClosed()) {
try (Jedis jedis = client.getResource()){
jedis.subscribe(this, channel);
log.info("Disconnect to redis channel: {}", channel);
break;
} catch (JedisConnectionException e) {
log.error("Failed connect to redis, reconnect it.", e);
if(!client.isClosed())
try {
Thread.sleep(1000);
} catch (InterruptedException ie){
break;
}
}
}
}, "RedisSubscribeThread");
subscribeThread.setDaemon(true);
subscribeThread.start();
log.info("Connected to redis channel:{}, time {} ms.", channel, (System.currentTimeMillis()-ct));
}