redis cluster

04/06/2022

demarrer le cluster

docker compose up -d redis-1 redis-2 redis-3 redis-4 redis-5 redis-6
docker exec -ti redis-1 redis-cli -p 7001 --cluster create 10.0.0.11:7001 10.0.0.12:7002 10.0.0.13:7003 10.0.0.14:7004 10.0.0.15:7005 10.0.0.16:7006 --cluster-replicas 1 --cluster-yes

try

docker exec -ti redis-1 redis-cli -c -p 7001 set a 123
docker exec -ti redis-1 redis-cli -c -p 7001 get a
# node server.js
# > get a
# -> Redirected to slot [15495] located at 10.0.0.13:7003
# "123"

health

docker exec -it redis-1 redis-cli -p 7001 --cluster check 10.0.0.11:7001

voir la topologie

docker exec -it redis-1 redis-cli -c -p 7001 cluster nodes

reshard.

docker exec -it redis-1 redis-cli -p 7001 --cluster reshard 10.0.0.11:7001

crash a master

docker exec -it redis-3 redis-cli -c -p 7003 debug segfault

supprimer un noeud

docker rm -f redis-3
docker compose up -d redis-3

rajouter le noeud

docker exec -it redis-1 redis-cli -p 7001 --cluster add-node 10.0.0.13:7003 10.0.0.11:7001 --cluster-slave --cluster-master-id 725b7618684414a1a304a673986dbb58c0ccf748

ou

docker exec -it redis-3 redis-cli -c -p 7003 Cluster meet 10.0.0.11 7001

oublier le vieux noeud

docker exec -it redis-1 redis-cli -c -p 7001 CLUSTER FORGET aca2d4ba7c2b5731453382da189a4b3e6a964ac5

docker exec -ti redis-1 redis-cli -p 7001 --cluster del-node 10.0.0.11:7001 aca2d4ba7c2b5731453382da189a4b3e6a964ac5

devenir slave d'un noeud

docker exec -it redis-3 redis-cli -c -p 7003 CLUSTER REPLICATE e8a26bc5ba1182d0ce67a1e3a558b66b85f488b9

compose file

#https://github.com/itsmetommy/docker-redis-cluster/tree/master
version: '3'

networks:
  redisnet:
    driver: bridge
    ipam:
      config:
        - subnet: 10.0.0.0/16

services:
  redis-1:
    container_name: redis-1
    image: redis:latest
    command: redis-server --port 7001 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
    networks:
      redisnet:
        ipv4_address: 10.0.0.11
    ports:
      - 7001:7001

  redis-2:
    container_name: redis-2
    image: redis:latest
    command: redis-server --port 7002 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
    networks:
      redisnet:
        ipv4_address: 10.0.0.12
    ports:
      - 7002:7002

  redis-3:
    container_name: redis-3
    image: redis:latest
    command: redis-server --port 7003 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
    networks:
      redisnet:
        ipv4_address: 10.0.0.13
    ports:
      - 7003:7003

  redis-4:
    container_name: redis-4
    image: redis:latest
    command: redis-server --port 7004 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
    networks:
      redisnet:
        ipv4_address: 10.0.0.14
    ports:
      - 7004:7004

  redis-5:
    container_name: redis-5
    image: redis:latest
    command: redis-server --port 7005 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
    networks:
      redisnet:
        ipv4_address: 10.0.0.15
    ports:
      - 7005:7005

  redis-6:
    container_name: redis-6
    image: redis:latest
    command: redis-server --port 7006 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
    networks:
      redisnet:
        ipv4_address: 10.0.0.16
    ports:
      - 7006:7006