85 lines
1.1 KiB
Bash
85 lines
1.1 KiB
Bash
parse_res() {
|
|
local line=${1%$'\r'}
|
|
|
|
case $line in
|
|
+*)
|
|
parse_simple "$line"
|
|
;;
|
|
-*)
|
|
parse_err "$line"
|
|
;;
|
|
:*)
|
|
parse_int "$line"
|
|
;;
|
|
\$*)
|
|
parse_bulk "$line"
|
|
;;
|
|
\**)
|
|
parse_arr "$line"
|
|
;;
|
|
*)
|
|
parse_other "$line"
|
|
esac
|
|
}
|
|
|
|
parse_simple() {
|
|
(( lines_left -= 1 ))
|
|
printf '%s\n' "${1:1}"
|
|
|
|
if [[ ${redis_cmd[0]} = SELECT && ${1:1} = OK ]]; then
|
|
table=${redis_cmd[1]}
|
|
fi
|
|
}
|
|
|
|
parse_int() {
|
|
(( lines_left -= 1 ))
|
|
printf '(integer) %d\n' "${1:1}"
|
|
}
|
|
|
|
parse_err() {
|
|
(( lines_left -= 1 ))
|
|
printf '(error) %s\n' "${1:1}"
|
|
}
|
|
|
|
parse_bulk() {
|
|
if [[ $1 = \$-1 ]]; then
|
|
(( lines_left -= 1 ))
|
|
printf '(nil)\n'
|
|
else
|
|
bulk=1
|
|
fi
|
|
}
|
|
|
|
parse_arr() {
|
|
if [[ $1 = \*-1 ]]; then
|
|
(( lines_left -= 1 ))
|
|
printf '(nil)\n'
|
|
elif [[ $1 = \*0 ]]; then
|
|
(( lines_left -= 1 ))
|
|
printf '(empty array)\n'
|
|
else
|
|
lines_left=${1:1}
|
|
arr=1
|
|
fi
|
|
}
|
|
|
|
parse_other() {
|
|
(( lines_left -= 1 ))
|
|
|
|
if (( arr )); then
|
|
printf '%d) ' "$arr"
|
|
(( arr++ ))
|
|
fi
|
|
|
|
if (( bulk )); then
|
|
printf '"'
|
|
fi
|
|
|
|
printf %s "$1"
|
|
|
|
if (( bulk )); then
|
|
printf '"'
|
|
fi
|
|
|
|
printf '\n'
|
|
}
|