Spring boot - Embedded redis : redis listen to local ip instead of localhost

Viewed 935

EDIT : cause found bellow

I have a problem with my embedded redis during IT tests, hope you'll help.

A bit of context : I am working on a spring boot backend, and we wrote for this application integration tests, using embedded redis.

Previously, I was working on another computer for this same project, and I haven't any problems. But I switch to a new one and since that, I can't reach my embedded redis anymore during the test.

Here is the stack :

Spring : org.springframework.boot:2.3.5.RELEASE
Redis embedded: com.github.fppt:1.16.0
I'm on macOS v11.4
maven 3.6.3

just start redis before test using :

redisServer = RedisServer.newRedisServer();
redisServer.start();
//Set host and port in properties from redisServer attributes
System.setProperty("spring.cache.redis.host", redisServer.getHost());
System.setProperty("spring.cache.redis.port", String.valueOf(redisServer.getBindPort()));

All work well from our CI (jenkins), and other people of the team (macos and windows).

  • I tried different java versions (11.0.11, 11.0.2, 14).
  • I tried from my IDE (Intellij) and from my terminal (iterm2)
  • I tried turning off my firewall
  • I tried other embedded redis
  • I tried set manually port(6379) using RedisServer.newRedisServer(port)

Nothing works...

Here the stack trace :

org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to 0.0.0.0:50152
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:282) ~[spring-data-redis-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:476) ~[spring-data-redis-2.3.5.RELEASE.jar:2.3.5.RELEASE]
    at org.springframework.data.redis.cache.DefaultRedisCacheWriter.execute(DefaultRedisCacheWriter.java:244) ~[spring-data-redis-2.3.5.RELEASE.jar:2.3.5.RELEASE]
...
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to 0.0.0.0:50152
    at redis.clients.jedis.Connection.connect(Connection.java:165) ~[jedis-3.3.0.jar:na]
...
Caused by: java.net.SocketTimeoutException: connect timed out
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[na:na]

Does anyone have an idea?

EDIT :

There is some news here ! After hours, I figure out one thing : If i change

System.setProperty("spring.cache.redis.host", redisServer.getHost());

by

System.setProperty("spring.cache.redis.host", my local ip);

I can reach my redis... The question now is more, why my local IP instead of 127.0.0.1 ? Due to MacOS 11.4 change ?

0 Answers
Related