Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save si9ma/5c48d47a83b6836222902dfb77a294fd to your computer and use it in GitHub Desktop.
Save si9ma/5c48d47a83b6836222902dfb77a294fd to your computer and use it in GitHub Desktop.

Revisions

  1. Richard Mathie revised this gist Mar 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Redis Cluster Setup with Docker Swarm.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ test the redis cluster
    docker run -it --rm --net mynet redis:3.2.6 redis-cli -c -h redis -p 6379
    ```

    > ```
    ```
    10.0.0.7:6379> set mykey1 1
    OK
    10.0.0.7:6379> set mykey2 2
  2. Richard Mathie renamed this gist Mar 29, 2017. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion README.md → Redis Cluster Setup with Docker Swarm.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,18 @@
    # Redis Cluster Setup with Docker Swarm

    ## Setup
    ```bash
    ./redis.sh
    ```

    ## Test
    test the redis cluster

    ```
    docker run -it --rm --net mynet redis:3.2.6 redis-cli -c -h redis -p 6379
    ```

    ```
    > ```
    10.0.0.7:6379> set mykey1 1
    OK
    10.0.0.7:6379> set mykey2 2
  3. Richard Mathie revised this gist Jan 12, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    test the redis cluster

    ```
    docker run -it --rm --net redis:3.2.6 redis-cli -c -h redis -p 6379
    docker run -it --rm --net mynet redis:3.2.6 redis-cli -c -h redis -p 6379
    ```

    ```
  4. Richard Mathie revised this gist Jan 12, 2017. 1 changed file with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@

    test the redis cluster

    ```
    docker run -it --rm --net redis:3.2.6 redis-cli -c -h redis -p 6379
    ```

    ```
    10.0.0.7:6379> set mykey1 1
    OK
    10.0.0.7:6379> set mykey2 2
    -> Redirected to slot [14119] located at 10.0.0.6:6379
    OK
    10.0.0.6:6379> set mykey3 3
    -> Redirected to slot [9990] located at 10.0.0.4:6379
    OK
    10.0.0.4:6379> get mykey1
    -> Redirected to slot [1860] located at 10.0.0.7:6379
    "1"
    10.0.0.7:6379> get mykey2
    -> Redirected to slot [14119] located at 10.0.0.6:6379
    "2"
    10.0.0.6:6379> get mykey3
    -> Redirected to slot [9990] located at 10.0.0.4:6379
    "3"
    10.0.0.4:6379>
    ```
  5. Richard Mathie created this gist Jan 12, 2017.
    26 changes: 26 additions & 0 deletions redis.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/bin/bash

    REDIS_CONFIG='port 6379
    cluster-enabled yes
    cluster-config-file nodes.conf
    cluster-node-timeout 5000
    appendonly yes'

    network=mynet

    docker service create --name redis \
    --network $network \
    --replicas=6 \
    -e REDIS_CONFIG="$REDIS_CONFIG" \
    -e REDIS_CONFIG_FILE="/usr/local/etc/redis/redis.conf" \
    redis:3.2.6-alpine sh -c 'mkdir -p $(dirname $REDIS_CONFIG_FILE) && echo "$REDIS_CONFIG" > $REDIS_CONFIG_FILE && cat $REDIS_CONFIG_FILE && redis-server $REDIS_CONFIG_FILE'

    sleep 2
    docker service ps redis --no-trunc

    # run the redis-trib.rb script (the docker inspect runs on the host and the echo output is passed the along to the ruby container)
    docker run -it --rm --net $network ruby sh -c "\
    gem install redis --version 3.2 \
    && wget http://download.redis.io/redis-stable/src/redis-trib.rb \
    && ruby redis-trib.rb create --replicas 1 \
    \$(getent hosts tasks.redis | awk '{print \$1 \":6379\"}') "