Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Complete Redis guide can be found from https://redis.io/

Redis is a open source in-memory database project that is hosted: https://redis.io/

Officially Redis does not support windows installation and is meant to be installed on Linux platform. Unofficial Windows package exists, but it does not have Redis project support. Therefore this material consists only Linux platform related content.

Redis can be installed even to one instance, however this test setup script installs three Redis instances, without slaves, so that the sharding can be tested. To test High Availability properly, also slave instances are needed.


Install REDIS

As an administrator install Redis using  platform packet manager

[root@hostname]# yum install redis

Start REDIS

Start REDIS. Script will start three Redis processes in to ports 6379, 6380, 6381 in one linux host

#!/bin/bash

master=( 6379 6380 6381 )

user=`whoami`
if [ ! -d "/var/run/redis" ]; then
 sudo mkdir -p /var/run/redis
 sudo chown "$user" -R /var/run/redis
fi

nodes=${#master[@]}

i=0
while [ "$i" -lt "$nodes" ]; do
 let port=${master[$i]}
 redis-server --requirepass redis.password --port "$port" --cluster-enabled yes --cluster-config-file "/var/run/redis/node${port}.conf" --daemonize yes
 let i=i+1
done

echo "Ok"

Initialize Redis

Initialize Redis. Script makes sure that process is alive and initializes each Redis process. Each redis process has to make aware of other Redis processes.

#!/bin/bash

master=( 6379 6380 6381 )

ok=0

for port in "${master[@]}"; do
        reply=`redis-cli -h 10.246.3.75 -p "$port" -a redis.password ping 2>/dev/null`
        if [ "$reply" == "PONG" ]; then
                let ok=ok+1
        else
                echo "$port is not replying."
        fi

done

if [ "$ok" -lt ${#master[@]} ]; then
        echo "All redis instances must be running before init. Please run redis-start.sh"
        exit
fi

MAX=16383
nodes=${#master[@]}

i=1
while [ "$i" -lt "$nodes" ]; do
        let port=${master[$i]}
        redis-cli -h 10.246.3.75 -p "${master[0]}" -a redis.password cluster meet 10.246.3.75 "$port" >/dev/null
        let i=i+1
done

i=0
while [  $i -le $MAX ]; do
        let node=$(($i % $nodes))
        let port=${master[$node]}
        redis-cli -h 10.246.3.75 -p "$port" -a redis.password cluster addslots "$i" >/dev/null
        let i=i+1
done

echo "Ok"

REDIS status check

Redis status check. Script prints status of each running Redis process.

#!/bin/bash

master=( 6379 6380 6381 )

nodes=${#master[@]}

i=0
while [ "$i" -lt "$nodes" ]; do
        let port=${master[$i]}
        echo "Status from $port"
        redis-cli -h 10.246.3.75 -p "$port" -a redis.password cluster info
        echo "---------"
        let i=i+1
done

Stop REDIS

Stop running Redis processes.

#!/bin/bash

master=( 6379 6380 6381 )

nodes=${#master[@]}

i=0
while [ "$i" -lt "$nodes" ]; do
        let port=${master[$i]}
        redis-cli -h 127.0.0.1 -p "$port" -a redis.password shutdown 2>/dev/null
        let i=i+1
done

echo "Ok"
  • No labels