This Project's Goal, Redis-Cluster used with Spring-Boot
-
First,Run docker-compose.yaml Without Application
- docker-compose up -d redis1 redis2 redis3 redis4 redis5 redis6
-
Second,Find ip addresses of redis containers
- docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
-
Third,Enter the container with exec command,
- docker exec -it redis1 bash
-
Fourth,Create Redis Cluster
- redis-cli --cluster create "redis1 IP Address":6379 "redis2 IP Address":6379 "redis3 IP Address":6379 "redis4 IP Address":6379 "redis5 IP Address":6379 "redis6 IP Address":6379 --cluster-replicas 1
-
Fifth,define Redis's dependencies in pom.xml
<!--Cache-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>${redis.version}</version> 3.0.0
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version> 3.9.0
</dependency>- Sixth,open application.properties and configure redis settings
spring.data.redis.cluster.nodes = redis1:6379,redis2:6379,redis3:6379, redis4:6379, redis5:6379, redis6:6379
spring.data.redis.cluster.max-redirects = 3- Seventh,Open RedisClusterConfig and edit the settings here according to application.properties (Note:getClusterNodes() method is Optional)
- Eighth,open Dockerfile and configure Owner settings,
- Added application build in docker-compose.yaml and run docker-compose up -d --build




