- Notifications
You must be signed in to change notification settings - Fork2
Example project for Spring boot, Lettuce redis cluster client and Testcontainers
License
Hixon10/spring-redis-cluster-testcontainers
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- This project uses this docker image -https://github.com/Grokzen/docker-redis-cluster
- This project is based on these ideas -testcontainers/testcontainers-java#3467 andhttps://levelup.gitconnected.com/testing-redis-clients-in-node-js-with-testcontainers-node-8221aafffc573467
- Testcontainers
The main idea of this example is manual NAT port mapping, which is implemented inru/hixon/springredisclustertestcontainers/RedisConfig.java
Manual NAT port mapping is needed, because of implementation details of the Redis cluster node discover algorithm. Redis Cluster uses gossip in order to auto-discover nodes. Each cluster node announces itsIP
andport
, and the application uses these IPs and PORTs for updating cluster topology (io.lettuce.core.cluster.topology.DefaultClusterTopologyRefresh
). So, the application has to be able to connect to these addresses.
The current example usesgrokzen/redis-cluster:6.0.7
docker image, which runs all Redis nodes in the same docker container. It is totally fine for image, which is created only for test purpose. Therefore, the application cannot use this image out of the box. It gets errors, like this:Unable to connect to [172.17.0.3/<unresolved>:7003]: connection timed out: /172.17.0.3:7003
. As you can see,redisUri
has docker container IP and an internal port. Obviously, theredisUri
is not accessible from the application.
There are 2 solutions to this problem.
- You could create docker image and set up correct settings for
cluster-announce-port
andcluster-announce-ip
- You could implement NAT port mapping on the application side. It is a workaround, but who cares, if it is only about tests. I've chosen this option.
About
Example project for Spring boot, Lettuce redis cluster client and Testcontainers
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.