我已经启用了AWS Redis Elastic Cache的集群模式,并配置了一个主节点和一个副本节点(分别在不同的可用区)。我正在使用Spring RedisTemplate和LettuceClientConfiguration,但是当我尝试将数据写入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: 在执行命令时发生错误;嵌套异常为io.lettuce.core.RedisCommandExecutionException: MOVED 15226 xxxx-redis-0001-002.xxx-redis.xxxx.xxxx.cache.amazonaws.com:6379
我正在使用AWS Redis配置端点URL通过Spring连接到Redis,并通过属性文件提供主机名:
@Configuration public class RedisCacheConfig {
[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: 在执行命令时发生错误;嵌套异常为io.lettuce.core.RedisCommandExecutionException: MOVED 15226 xxxx-redis-0001-002.xxx-redis.xxxx.xxxx.cache.amazonaws.com:6379
我正在使用AWS Redis配置端点URL通过Spring连接到Redis,并通过属性文件提供主机名:
@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();
}
我认为Lettuce正在自动发现集群并尝试写入副本节点。
请问有人能帮助我如何使用Lettuce客户端与AWS Redis集成吗?