Add extra processing of special commands
This commit is contained in:
parent
68168b91fe
commit
657db23236
10
lib/cli.sh
10
lib/cli.sh
|
@ -6,10 +6,9 @@ get_cmd() {
|
||||||
|
|
||||||
parse_cmd() {
|
parse_cmd() {
|
||||||
local cmd=( ) arg
|
local cmd=( ) arg
|
||||||
declare -n cmd_sent=$1
|
declare -n serialized=$1
|
||||||
declare -n serialized=$2
|
|
||||||
|
|
||||||
route_cmd "$3"
|
route_cmd "$2"
|
||||||
|
|
||||||
serialized=*${#cmd[@]}$'\r\n'
|
serialized=*${#cmd[@]}$'\r\n'
|
||||||
|
|
||||||
|
@ -56,9 +55,10 @@ parse_word() {
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! (( ${#cmd[@]} )); then
|
if ! (( ${#cmd[@]} )); then
|
||||||
cmd_sent=${arg^^}
|
redis_cmd=( "${arg^^}" )
|
||||||
cmd+=( "\$${#arg}"$'\r\n'"$cmd_sent"$'\r\n' )
|
cmd=( "\$${#arg}"$'\r\n'"${arg^^}"$'\r\n' )
|
||||||
else
|
else
|
||||||
|
redis_cmd+=( "$arg" )
|
||||||
cmd+=( "\$${#arg}"$'\r\n'"$arg"$'\r\n' )
|
cmd+=( "\$${#arg}"$'\r\n'"$arg"$'\r\n' )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,10 @@ parse_res() {
|
||||||
parse_simple() {
|
parse_simple() {
|
||||||
(( lines_left -= 1 ))
|
(( lines_left -= 1 ))
|
||||||
printf '%s\n' "${1:1}"
|
printf '%s\n' "${1:1}"
|
||||||
|
|
||||||
|
if [[ ${redis_cmd[0]} = SELECT && ${1:1} = OK ]]; then
|
||||||
|
table=${redis_cmd[1]}
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_int() {
|
parse_int() {
|
||||||
|
|
|
@ -28,7 +28,14 @@ fi
|
||||||
###
|
###
|
||||||
|
|
||||||
while get_cmd line; do
|
while get_cmd line; do
|
||||||
parse_cmd redis_cmd redis_line "$line"
|
redis_cmd=( )
|
||||||
|
|
||||||
|
parse_cmd redis_line "$line"
|
||||||
|
|
||||||
|
if [[ ${redis_cmd[0]} = EXIT ]]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
redis_send "$redis_line"
|
redis_send "$redis_line"
|
||||||
|
|
||||||
lines_left=1
|
lines_left=1
|
||||||
|
|
Loading…
Reference in New Issue