How to connect AWS Elasticache Redis cluster to Spring Boot app?


I have Spring Boot app which connects to Redis cluster, using Jedis Connection Factory:

and reading list of nodes from application.yml:

Now we want to switch to Elasticache since we are hosting our Redis cluster on AWS anyway.
It would be done quite easily. If AmazonElastiCache lib could be used.
Then we could just connect to Elasticache cluster with AWS credentials, pull available nodes put it in the list and pass it to Jedis instead hardcoding them in application.yml, like:

But DevOps team said that they can’t configure AWS access on all labs and they have reasons for it. Also instead of connecting to AWS and pulling all available clusters we need to connect to specific one by URL.

So I tried to pass Elasticache cluster url directly to Jedis as standalone and as a cluster in application.yml configuration.
In both cases connection is established, but when App tries to write to Elasticache its gets MOVED exception:

Which as I understand means that App tried to write to one of the nodes in Elasticache, but wasn’t able to connect.

So the question would be is there a way to connect to Elasticache Redis cluster from Spring Boot app using only Elasticache cluster URL?

I know that it’s doable if Elasticache Memecache is used.
Also Jedis driver is not a hard requirement.

Thank you.


After some research we learned that if AWS Elasticache cluster end-point is set as a node in RedisClusterConfiguration then driver (Jedis or Lettuce) is able to connect and find all the nodes in a Elasticache cluster. Also if one of the nodes goes down driver is able to communicate with Elasticache cluster through some other node.

We migrated to Lettuce driver while working on this upgrade as well, since Lettuce is default driver provided in Spring Boot Redis Started and supports latest Redis versions. Lettuce connections are designed to be thread-safe too, Jedis not.

Code example:

Leave a Reply