生菜客户端配置以连接到AWS Redis Elasticache

时间:2019-08-15 12:43:01

标签: amazon-web-services client amazon-elasticache lettuce

我在集群模式下配置了aws redis弹性缓存,并且我有一个主副本和一个副本(都在单独的可用区中)。我与LettuceClientConfiguration一起使用Spring RedisTemplate,但尝试写入Redis时却出现以下错误:-

[http-nio-8080-exec-5]错误c.a.w.c.auth.Login-身份验证失败:执行错误;嵌套的异常是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 在org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:54) 在org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:52) 在org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41) 在org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44) 在org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42) 在org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:268) 在org.springframework.data.redis.connection.lettuce.LettuceHashCommands.convertLettuceAccessException(LettuceHashCommands.java:471) 在org.springframework.data.redis.connection.lettuce.LettuceHashCommands.hGet(LettuceHashCommands.java:172) 在org.springframework.data.redis.connection.DefaultedRedisConnection.hGet(DefaultedRedisConnection.java:926) 在org.springframework.data.redis.core.DefaultHashOperations.lambda $ get $ 0(DefaultHashOperations.java:53) 在org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224) 在org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)

我正在使用aws redis配置端点URL通过spring连接到redis,并且通过属性文件提供了主机名:-

@配置 公共类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集成吗?

0 个答案:

没有答案