Git Product home page Git Product logo

redis-cluster-docker-swarm's Introduction

Redis Cluster Cache for Docker Swarm

CircleCI

Quick and dirty Redis cluster taking advantage of Redis Sentinel for automatic failover. Persistence is turned off by default.

Usage

  1. Setup docker swarm
  2. Create a overlay network:
docker network create --attachable --driver overlay redis
  1. Modify scripts/docker-compose.yml to how you want to deploy the stack.
  2. Run scripts/bootstrap.sh.
bash scripts/bootstrap.sh latest
  1. Connect to with redis-cli
docker run --rm --network redis -ti redis:4.0.11-alpine redis-cli -h redis

To access the redis cluster outside of docker, port 6379 needs to be expose. This can be done by adding ports to the docker-compose file:

...
  redis:
    image: thomasjpfan/redis-look
    ports:
      - "6379:6379"
...

Details

A docker service called redis-zero is created to serve as the initial master for the redis sentinels to setup. The redis-look instances watches the redis sentinels for a master, and connects to redis-zero once a master has been decided. Once the dust has settled, remove the redis-zero instance and wait for failover to take over so a new redis-master will take over. Use redis-utils to reset sentinels so that its metadata is accurate with the correct state.

The use of redis-zero as a bootstrapping step allows for the docker-compose.yml to provide only the long running services:

version: '3.1'

services:

  redis-sentinel:
    image: thomasjpfan/redis-sentinel
    environment:
      - REDIS_IP=redis-zero
      - REDIS_MASTER_NAME=redismaster
    deploy:
      replicas: 3
    networks:
      - redis

  redis:
    image: thomasjpfan/redis-look
    environment:
      - REDIS_SENTINEL_IP=redis-sentinel
      - REDIS_MASTER_NAME=redismaster
      - REDIS_SENTINEL_PORT=26379
    deploy:
      replicas: 3
    networks:
      - redis

networks:
  redis:
    external: true

Scaling

From now on just scale redis to expand the number of slaves or scale redis-sentinel to increase the number of sentinels.

redis-cluster-docker-swarm's People

Contributors

thomasjpfan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.