Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 49 lines (48 sloc) 1.2 KB
#!/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
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