简体   繁体   English

如何为 Spring 数据访问配置 ElastiCache Redis

[英]How to configure ElastiCache Redis for Spring Data Access

I am trying to setup ElastiCache to use with a Java Application.我正在尝试设置 ElastiCache 以与 Java 应用程序一起使用。 I have based my setup based on this documentation: https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/BestPractices.html我的设置基于此文档: https : //docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/BestPractices.html

The EC2 instance where the Java (8) App runs is in a VPC. Java (8) 应用程序运行所在的 EC2 实例位于 VPC 中。 I have tried an ElastiCache instance both in VPC and no VPC.我在 VPC 和非 VPC 中都尝试过 ElastiCache 实例。 However, I always got,然而,我总是得到,

redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused

If I install Redis myself on an EC2 instance and connect to it, the app is able to connect to the Redis Cache!如果我自己在 EC2 实例上安装 Redis 并连接到它,应用程序就能够连接到 Redis 缓存!

I have setup proper authorization with Security-group from EC2 to Cache-Security but no luck.我已经设置了从 EC2 到缓存安全的安全组的正确授权,但没有运气。 I just can't make the 'connection'.我只是无法建立“连接”。 Any sample connection snippet would be really helpful.任何示例连接片段都会非常有帮助。

Redis is setup this way in the APP Config: Redis 在 APP Config 中是这样设置的:

    @Bean
    public JedisConnectionFactory redisConnectionFactory() {
    JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
    redisConnectionFactory.setHostName(<cache-node>);
    redisConnectionFactory.setPort(6397);
    redisConnectionFactory.setUsePool(true);
    redisConnectionFactory.setTimeout(3600);
    return redisConnectionFactory;
   }

The various versions:各种版本:

Jedis- 2.6.2, Spring- 4.1.6, Spring-data-> 1.5.0
telnet redis-ip 6397

判断redis是否可以连接

redisConnectionFactory.setPort(6397);

应该是

redisConnectionFactory.setPort(6379); //default redis port

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM