0
votes

I'm using Spring boot 2.2.5 and Spring data redis and bitnami/redis-sentinel sentinel docker image.

bitnami/redis-sentinel docker image works fine with docker compose.

I can connect to the redis with redis-cli. (cli shows 127.0.0.1:6379 connected)

But in my local Spring boot application, it doesn't work. Error trace is like:

org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 172.28.0.2:6379
at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:109) ~[spring-data-redis-2.2.5.RELEASE.jar:2.2.5.RELEASE]

Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to 172.28.0.2:6379
    at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78) ~[lettuce-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]

Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /172.28.0.2:6379
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261) ~[netty-transport-4.1.45.Final.jar:4.1.45.Final]

the IP address 172.28.0.2 is redis master ip in the docker image.

My sentinel host configuration is like below, 127.0.0.1:26379,127.0.0.1:26379,127.0.0.1:26379

I guess my application gets well the master info via localhost sentinel configuration.

Then Why is my application finding 172.28.0.2:6379 for master instead of 127.0.0.1:6379 ?

Do I need to change the address in that docker image or Should I run my app on the docker also?

Any help would be appreciated!

1
do you use docker-compose? if yes could you show your docker-compose file.MevlütÖzdemir
Yes and I just attached my answer. Thanks.DKWoo

1 Answers

1
votes

I just solved my problem by adding REDIS_MASTER_HOST=127.0.0.1 (thatw was 'redis' originally) at environment in docker-compose. I figured out that there is 172.28.0.2 6379 set for monitor reids master in redis-sentinel.conf of running container and it didn't changed with container name 'redis'.

After that, my springb boot application with lettuce client can connect to redis without any problem in local machine.