我启用了集群模式下的 aws redis 弹性缓存,并且我有一个主副本和一个副本(都在单独的可用区中(。我正在使用Spring RedisTemplate和LettuceClientConfiguration,但是当我尝试写入redis时出现以下错误:-
[http-nio-8080-exec-5] 错误 c.a.w.c.auth.Login - 身份验证失败:执行时出错;嵌套异常为 io.lettuce.core.RedisCommandExecutionException: 已移动 15226 xxxx-redis-0001-002.xxx-redis.xxxx.xxxx.cache.amazonaws.com:6379 org.springframework.data.redis.RedisSystemException: 执行错误;嵌套异常是 io.lettuce.core.RedisCommandExecutionException: MOVE 15226 xxxx-redis-0001-002.xxx-redis.xxxx.xxxx.cache.amazonaws.com:6379 at org.springframework.data.redis.connection.lettuce.lettuce.lettuceExceptionConverter.convert(LettuceExceptionConverter.java:54( at org.springframework.data.redis.connection.lettuce.lettuce.lettuceExceptionConverter.convert(LettuceExceptionConverter.java:52( at org.springframework.data.redis.connection.lettuce.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.lettuce.lettuceConnection.convertLettuceAccessException(LettuceConnection.java:268( at org.springframework.data.redis.connection.lettuce.lettuce.LettuceHashCommand.convertLettuceAccessException(LettuceHashCommand.java:471( at org.springframework.data.redis.connection.lettuce.lettuce.LettuceHashCommand.hGet(LettuceHashCommand.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(
我正在使用 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();
}
}
我相信生菜会自动发现集群并尝试写入副本节点。
有人可以帮助我如何使用生菜客户端与 AWS Redis 集成吗?
您正在使用RedisStandaloneConfiguration,它告诉生菜尝试以单一模式而不是集群模式运行redis。对于集群模式,您应该使用 RedisClusterConfiguration 类似这样的东西 ->新的 RedisClusterConfiguration(Arrays.asList(host+port((