4
votes

I have integrated redis to my spring web application using jedis (redis is supporting from AWS Elastic cache). It is working fine with single node to write and read with single jedis connection factory.

I now need to extended it to a cluster for writing into primary node and reading from secondary nodes. i.e If one goes down then replication happen automatically by AWS, in that case the host name, with which I will connect , will be change.

How can read the new node that came into picture?

How can i connect to this from spring container (I mean XML file)?

please, any one have useful suggestions, to achieve above scenario.

I would appreciate any links or code that may be helpful to over come the above problem.

As of now, I am using one connection factory, with jedis and redis template for manipulation.

2
Hi, can you share the code in spring boot doing this? For me is still connection refuse on AWS redisuser2670818

2 Answers

5
votes

You don't have to do anything on your side, AWS ElastiCache will handle the failover.

You have a redis cluster with two nodes, Primary and Replica. If something happens to the Primary node, there is an automatic failover to the Replica node. The failover happens at the replication group node DNS level

It is very important that your application connects to the Replication Group Node and not to the primary node url/ip directly

You can find the replication group endpoint in ElastiCache -> Replication Groups -> (select your replication group) And in the bottom section there's Node Group Details Primary Endpoint example myReplicationGroup.8asdas.ng.0001.use1.cache.amazonaws.com:6379

In case of failover there is a bit of downtime. From my experience it's less than 1 minute.

After the failed node comes back, it may became the Secondary node and stay like that if you have Multi-AZ enabled

1
votes

When any node goes down, everything is happening without any intervention from your side. You also don't need to write any code for this fail-over. All you have to do is to use the DNS name of your Redis Elasticache cluster and not its IP.
For example lets say you have 1 master and 2 slaves. When the master goes down a new slave will be elected to be master automatically and AWS will change the DNS of the master to point to the slave IP which became the new master. And it will also spin a new slave replacing the one converted to master and updating the DNS record of the slave to point to the new IP address. So you don't need to worry about anything because the host names remain the same, only the IPs behind them will change. Here you can find more details with what's happening behind the hood: Auto Failover for Amazon ElastiCache for Redis