I have 1 master(6379), 1 slave(6380), and 3 sentinels(26379, 26380, 26381) running on docker container master and slave are connected and up even sentinels are giving right information about master-slave.
When I do my query with master and slave both up, it is running fine and I could see(through exposed ports) the same data in both(sync between master and slave is fine).
When I pause master, sentinels act and make slave new master but this time when I try to access redis through my code it is not able to connect and Redis command timed out nested exception is io.lettuce.core.RedisCommandTimeoutException is thrown.
docker-compose file
services:
db:
image: mysql:5.7
restart: always
environment:
- MYSQL_DATABASE=inward
# So you don't have to use root, but you can if you like
#- MYSQL_USER=test
# You can use whatever password you like
#- MYSQL_PASSWORD=test
# Password for root access
- MYSQL_ROOT_PASSWORD=unroot
ports:
# <Port exposed> : < MySQL Port running inside container>
- 3309:3306
master:
image: redis
ports:
- 6379:6379
slave:
image: redis
command: >
bash -c "echo 'port 6380' > slave.conf &&
echo 'replicaof master 6379' >> slave.conf &&
cat slave.conf &&
redis-server slave.conf"
links:
- master
ports:
- 6380:6380
sentinel:
image: redis
command: >
bash -c "echo 'port 26379' > sentinel.conf &&
echo 'dir /tmp' >> sentinel.conf &&
echo 'sentinel monitor mymaster master 6379 2' >> sentinel.conf &&
echo 'sentinel down-after-milliseconds mymaster 5000' >> sentinel.conf &&
echo 'sentinel parallel-syncs mymaster 1' >> sentinel.conf &&
echo 'sentinel failover-timeout mymaster 5000' >> sentinel.conf &&
cat sentinel.conf &&
redis-server sentinel.conf --sentinel"
links:
- master
- slave
ports:
- 26379:26379
sentinel1:
image: redis
command: >
bash -c "echo 'port 26380' > sentinel.conf &&
echo 'dir /tmp' >> sentinel.conf &&
echo 'sentinel monitor mymaster master 6379 2' >> sentinel.conf &&
echo 'sentinel down-after-milliseconds mymaster 5000' >> sentinel.conf &&
echo 'sentinel parallel-syncs mymaster 1' >> sentinel.conf &&
echo 'sentinel failover-timeout mymaster 5000' >> sentinel.conf &&
cat sentinel.conf &&
redis-server sentinel.conf --sentinel"
links:
- master
- slave
ports:
- 26380:26380
sentinel2:
image: redis
command: >
bash -c "echo 'port 26381' > sentinel.conf &&
echo 'dir /tmp' >> sentinel.conf &&
echo 'sentinel monitor mymaster master 6379 2' >> sentinel.conf &&
echo 'sentinel down-after-milliseconds mymaster 5000' >> sentinel.conf &&
echo 'sentinel parallel-syncs mymaster 1' >> sentinel.conf &&
echo 'sentinel failover-timeout mymaster 5000' >> sentinel.conf &&
cat sentinel.conf &&
redis-server sentinel.conf --sentinel"
links:
- master
- slave
ports:
- 26381:26381
app:
build:
context: ./
dockerfile: Dockerfile
depends_on:
- db
links:
- master
- slave
- sentinel
- sentinel1
- sentinel2
working_dir: /app
command: [sh, -c, 'mkdir -p ~/logs/; cd /src ; mvn clean spring-boot:run -Dspring.profiles.active=local -DLOG_DIR=/root/logs/ -DLOG_FILE=hubstamper.log']
ports:
- 8080:8080
volumes:
- "${HOME}/.m2:/root/.m2"
and application.properties file is
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=sentinel:26379,sentinel1:26380,sentinel2:26381
Please help me with this.