简体   繁体   中英

Redis PubSub Reconnect with Jedis

Trying to include the code related to azure redis autoreconnect if any.network error occurred in Redis PubSub connection. Any help/advice would be appreciable. Below is my Redis Config code.

 public class RedisConfig 
   {    
    @Bean
    JedisConnectionFactory jedisConnectionFactory() {
        JedisConnectionFactory jedis = new JedisConnectionFactory();
        jedis.setHostName("redishostname");
        jedis.setPassword("redispassword");
        jedis.setPort(redisport);
        return jedis;
    }

    @Bean
    public RedisTemplate<String, Object> redisTemplate() {
        final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
        template.setConnectionFactory(jedisConnectionFactory());
        template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
        return template;
    }   

    @Bean
    RedisMessageListenerContainer redisContainer() {
        final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(jedisConnectionFactory());
        container.setTaskExecutor(Executors.newFixedThreadPool(4));     
        return container;
    }
    }

Please see the following client library specific guidance ( link ) for Azure Cache for Redis and the information available for Jedis (Java) .

There is a PoolUsage.java example and a ClusterUsage.java example.

As for a specific example for PubSub Reconnect, please see the following Stack Overflow post: jedis pubsub and timeouts: how to listen infinitely as subscriber?

private AkkaStarter2(){
//0 specifying no timeout.. Overlooked this 100 times
sub = new Jedis(REDISHOST, REDISPORT,0);
akkaListener = new AkkaListener();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM