Error connecting to Redis from Spring Boot

128 Views Asked by At

I am using spring boot version 2.1.3 and trying to connect to cluster redis but I am getting

Cannot retrieve initial cluster partitions from initial URIs

then I upgraded to spring boot version 3.2.2 and start getting another error

io.lettuce.core.RedisException: Cannot obtain initial Redis Cluster topology

any idea why I am not able to connect, although the redis server is accessable and I am passing the correct username, password, host and port to it.

1

There are 1 best solutions below

1
Ajaj Ali On

You can create a configuration for LettuceConnectionFactory.

 @Bean
    public LettuceConnectionFactory redisStandAloneConnectionFactory() {
        return new LettuceConnectionFactory(new RedisStandaloneConfiguration("127.0.0.1", 6379));
    }

If you have properties file you can configure like

# Redis Config
spring.cache.type=redis
spring.data.redis.host=127.0.0.1
spring.data.redis.port=6379

Hope it helps.