I am trying to start my application with Redis Sentinel in my local System.
When I start the application its being stopped with below error. I have started redis in my windows machine with master on 6379 port, replica on 6380 and 6381 ports and sentinels on 26379,26380,26381 ports. I can connect to redis servers with redis-cli command.
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name \u0027redisConnectionFactory\u0027 defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method \u0027redisConnectionFactory\u0027 threw exception; nested exception is java.lang.IllegalStateException: Invalid redis sentinel property \u0027127.0.0.1\u0027"
Below is my redis config class.
@Configurationpublic class RedisConfigurations { private final RedisProperties redisProperties; @Value("${spring.redis.host}") private String redisHost; @Value("${spring.redis.port}") private Integer redisPort; @Value("${spring.redis.database}") private Integer database; @Value("${spring.redis.password}") private String redisPwd; @Bean protected LettuceConnectionFactory redisConnectionFactory() { RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration() .master(redisProperties.getSentinel().getMaster()); redisProperties.getSentinel().getNodes().forEach(s -> sentinelConfig.sentinel(s, redisProperties.getPort())); sentinelConfig.setPassword(RedisPassword.of(redisProperties.getPassword())); sentinelConfig.setDatabase(database); return new LettuceConnectionFactory(sentinelConfig, LettuceClientConfiguration.defaultConfiguration()); } public <T> Jackson2JsonRedisSerializer<T> configureJackson2JsonRedisSerializer(Class<T> t) { Jackson2JsonRedisSerializer<T> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(t); jackson2JsonRedisSerializer.setObjectMapper(new ObjectMapper()); return jackson2JsonRedisSerializer; } @Bean public RedisTemplate<String, Object> redisTemplate() { final RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setHashKeySerializer(new GenericToStringSerializer<>(Object.class)); redisTemplate.setValueSerializer(configureJackson2JsonRedisSerializer(Object.class)); redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setConnectionFactory(redisConnectionFactory()); return redisTemplate; }
And below is my application yml props.
spring: application: name: some-app profiles: active: local main: allow-bean-definition-overriding: true redis: host: 127.0.0.1 port: 26380 database: 0 sentinel: master: master nodes: - 127.0.0.1 - 127.0.0.1 - 127.0.0.1 lettuce: shutdown-timeout: 100ms pool: max-active: 5 min-idle: 2 max-wait: 1ms