SHARE
TWEET

Untitled

a guest Oct 12th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #./assignSlots.sh 7001 5 redis-cluster-m-
  3. readonly STARTING_PORT=${1:-0}
  4. readonly NUM_MASTERS=${2:-0}
  5. readonly NAME_PREFIX=${3:-"redis-cluster-m-"}
  6. readonly MAX_SLOT=$((16383))
  7. readonly SLOT_RANGE=$(((MAX_SLOT + NUM_MASTERS - 1) / NUM_MASTERS))
  8. readonly LOCAL_CONTAINER_ID=$(docker ps -f name="$NAME_PREFIX" -q | head -n 1)
  9. readonly LOCAL_PORT=$(docker inspect --format='{{index .Config.Labels "com.docker.swarm.service.name"}}' "$LOCAL_CONTAINER_ID" | sed 's|.*-||')
  10. for ((port = STARTING_PORT, endPort = STARTING_PORT + NUM_MASTERS, slot = 0; port < endPort; port++)) do
  11.   end_slot=$((slot + SLOT_RANGE))
  12.   end_slot=$((end_slot > MAX_SLOT ? MAX_SLOT : end_slot))
  13.   host=$([ "$LOCAL_PORT" == $port ] && echo "127.0.0.1" || echo "$NAME_PREFIX$port")
  14.   echo "CLUSTER ADDSLOTS $slot - $end_slot"
  15.   # shellcheck disable=SC2046
  16.   docker exec -it "$LOCAL_CONTAINER_ID"\
  17.     redis-cli -h "$host" -p "$port"\
  18.       CLUSTER ADDSLOTS $(seq "$slot" "$end_slot")
  19.   slot=$((end_slot + 1));
  20. done
  21. exit 0
RAW Paste Data
Top