Search code examples
spring-bootredisspring-data-redisamazon-elasticache

Connecting to AWS ElastiCache for Redis from Spring boot application


Currently I am doing an implementation of a caching module in spring-boot. The idea is to connect with AWS ElastiCache for Redis. For this I know there are couple of ways to achieve this. I will list those below.

First way

I can use spring-boot-starter-data-redis with jedis or lettuce. That involves some configuration and I can get the job done. (I prefer doing this way)

Second way

I can use spring-cloud-aws-dependencies, spring-boot-starter-data-redis, spring-cloud-starter-aws and aws-java-sdk-elasticache. In this way I think it is more focused on AWS ElastiCache and I don't know whether I can connect with a local redis server easily.

My question is, are there any other ways to connect with AWS ElastiCache and expert opinion on what would be the best approach for this. I wanna filter out the best robust way to do this such that it will be usable and applicable in future appliances. Thank you!


Solution

  • My implementation is done with the caching module and I will explain the approach I took. In-fact it all depends on use-cases. For my use-case I did follow the first approach which is using spring-boot-starter-data-redis with jedis or lettuce. That did involve some configuration and I could get the job done. However this is not the most recent and easiest approach. There are drawbacks of using this way as well such as it has manual configuration and I had to write couple of classes with beans including whole lot of unit testing. However, I had more control over what is going on and how. I was even able to integrate spring in-memory caching and nicely control everything via application.yml file. Most importantly it is very easy and working fine with AWS ElastiCache for Redis as well as local Redis server.

    I can briefly explain the second approach and it would be good if the prime focus is AWS ElastiCache for Redis. That is by using spring-cloud-starter-aws and aws-java-sdk-elasticache. It is an easy approach and quick. It is more likely plug and play. I was not able to do whole lot of changes to its functionality other than what is offered. Probably possible to do changes and I didn't go that deep. So this would be the ideal solution to keep the code simple and for deployments focused on AWS ElastiCache for Redis.

    Thank you!