Skip to content

muharremkoc/spring-learn-redis-cluster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-learn-redis-cluster

This Project's Goal, Redis-Cluster used with Spring-Boot

Installation

  • First,Run docker-compose.yaml Without Application

    • docker-compose up -d redis1 redis2 redis3 redis4 redis5 redis6

    image

  • Second,Find ip addresses of redis containers

    • docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

    image

  • 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)

image

  • Eighth,open Dockerfile and configure Owner settings,

image

  • Added application build in docker-compose.yaml and run docker-compose up -d --build

image

Muharrem Koç

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published