Lettuce客户端配置连接到AWS Redis Elasticache。

4
我已经启用了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 {
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集成吗?

1个回答

0

您正在使用 RedisStandaloneConfiguration,这告诉 Lettuce 尝试以单一模式而非集群模式运行 Redis。对于集群模式,您应该使用 RedisClusterConfiguration,类似于这样 -> new RedisClusterConfiguration(Arrays.asList(host+port))


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接