Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Example project for Spring boot, Lettuce redis cluster client and Testcontainers

License

NotificationsYou must be signed in to change notification settings

Hixon10/spring-redis-cluster-testcontainers

Repository files navigation

Credits

  1. This project uses this docker image -https://github.com/Grokzen/docker-redis-cluster
  2. 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
  3. Testcontainers

How it works

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.

  1. You could create docker image and set up correct settings forcluster-announce-port andcluster-announce-ip
  2. 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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp