-
Notifications
You must be signed in to change notification settings - Fork 4
/
func.sh
57 lines (51 loc) · 1.31 KB
/
func.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
function endless_input {
i=0
while : ; do
VAL=`openssl rand -base64 32`
KEY=key`openssl rand -base64 32`
PORT=`master_port`
redis-cli -p $PORT SET $KEY $VAL &>/dev/null
i=$((i+1))
if [ "$(($i % 100))" -eq "0" ]; then
printf "\033c"
echo "======================================================"
echo "Master is on port $PORT"
echo "7777 `redis-cli -p 7777 info keyspace 2>/dev/null`"
echo "6666 `redis-cli -p 6666 info keyspace 2>/dev/null`"
echo "8888 `redis-cli -p 8888 info keyspace 2>/dev/null`"
fi
done
}
master_pid() {
port=`master_port`
echo `lsof -i:$port | grep LISTEN | awk -F' ' 'NR==1{print $2}'`
}
master_port() {
echo `redis-cli -p 26379 sentinel get-master-addr-by-name mymaster | awk -F'"' 'NR==2{print $1}'`
}
dir_port() {
case $1 in
'6666') echo 'redis1';;
'7777') echo 'redis2';;
'8888') echo 'redis3';;
esac
}
function startredis {
pushd $1 > /dev/null
redis-server config > /dev/null &
popd > /dev/null
}
function killmaster {
while : ; do
sleep 10
PID=`master_pid`
PORT=`master_port`
DIRNAME=`dir_port $PORT`
echo "killing $DIRNAME on port $PORT"
kill -9 $PID 2>&1 > /dev/null
sleep 10
echo "starting $DIRNAME on port $PORT"
startredis $DIRNAME
done
}