I have aws redis elastic cache configured in cluster mode enabled and I have one primary and one replica (both in separate availability zones). I am using Spring RedisTemplate along with LettuceClientConfiguration but getting below error when I try to write into redis:-
[http-nio-8080-exec-5] ERROR c.a.w.c.auth.Login - Authentication failed: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: MOVED 15226 xxxx-redis-0001-002.xxx-redis.xxxx.xxxx.cache.amazonaws.com:6379 org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: MOVED 15226 xxxx-redis-0001-002.xxx-redis.xxxx.xxxx.cache.amazonaws.com:6379 at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:54) at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:52) at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41) at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44) at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42) at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:268) at org.springframework.data.redis.connection.lettuce.LettuceHashCommands.convertLettuceAccessException(LettuceHashCommands.java:471) at org.springframework.data.redis.connection.lettuce.LettuceHashCommands.hGet(LettuceHashCommands.java:172) at org.springframework.data.redis.connection.DefaultedRedisConnection.hGet(DefaultedRedisConnection.java:926) at org.springframework.data.redis.core.DefaultHashOperations.lambda$get$0(DefaultHashOperations.java:53) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
I am using aws redis configuration endpoint url to connect to redis through spring and I provide the host name through properties file:-
@Configuration public class RedisCacheConfig {
private static Logger logger = LoggerFactory.getLogger(RedisCacheConfig.class);
@Value("${redishost:localhost}")
private String host;
@Value("${redisport:6379}")
private int port;
@Value("${redisauth:}")
private String redisauth;
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration conf = new RedisStandaloneConfiguration(host, port);
if (!StringUtils.isEmpty(redisauth)) {
logger.info("Setting redis auth");
conf.setPassword(redisauth);
LettuceClientConfiguration clientConf = LettuceClientConfiguration.builder().useSsl().disablePeerVerification().build();
return new LettuceConnectionFactory(conf, clientConf);
} else {
return new LettuceConnectionFactory(conf);
}
}
@Bean
public RedisTemplate<String, ?> redisTemplate() {
RedisTemplate<String, ?> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory());
return template;
}
@Bean
public CacheService getService() {
return new RedisCacheService();
}
}
I believe lettuce is auto discovering the cluster and trying to write to replica node.
Can someone help me how should I integrate with aws redis using lettuce client?