forked from caquino/redis-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis-bash-cli
executable file
·51 lines (51 loc) · 1.25 KB
/
redis-bash-cli
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
#!/bin/bash
# https://github.com/caquino/redis-bash
# Poor man profiling - uncoment the next 2 lines
#set -x
#PS4='$(date "+%s.%N ($LINENO) + ")'
source /usr/share/redis-bash/redis-bash-lib 2> /dev/null
if [ $? -ne 0 ]; then
LIBFOLDER=${0%/${0##*/}}
source ${LIBFOLDER}/redis-bash-lib 2> /dev/null
if [ $? -ne 0 ]; then
echo "can't find redis-bash-lib in /usr/share/redis-bash or ${LIBFOLDER}"
exit 127
fi
fi
REDISHOST=localhost
REDISPORT=6379
REPEAT=1
DELAY=0
while getopts ":h:n:p:r:a:i:" opt
do
case ${opt} in
h) REDISHOST=${OPTARG};;
n) REDISDB=${OPTARG};;
p) REDISPORT=${OPTARG};;
r) REPEAT=${OPTARG};;
a) AUTH=${OPTARG};;
i) DELAY=${OPTARG};;
esac
done
shift $((${OPTIND} - 1))
if [ "${REDISHOST}" != "" ] && [ "${REDISPORT}" != "" ]
then
exec 6<>/dev/tcp/${REDISHOST}/${REDISPORT} # open fd
if [ $? -ne 0 ]; then
exit 1
fi
else
echo "Wrong arguments"
exit 255
fi
[ "${AUTH}" != "" ] && redis-client 6 AUTH ${AUTH} > /dev/null
[ "${REDISDB}" != "" ] && redis-client 6 SELECT ${REDISDB} > /dev/null
for ((z=1;z<=${REPEAT};z++))
do
redis-client 6 "${@}"
if [ $? -ne 0 ]; then
exit 1
fi
[ ${DELAY} -gt 0 ] && sleep ${DELAY}
done
exec 6>&- #close fd