Created
March 23, 2017 06:25
-
-
Save ruiwen/6079252807cf42b95146e17055fbb970 to your computer and use it in GitHub Desktop.
Bash function to translate redis commands to their pipelined equivalent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bash function to translate redis commands to their pipelined equivalent | |
# | |
# eg. | |
# | |
# $ redis_p HMSET key value key1 value1 | |
# *5 | |
# $5 | |
# HMSET | |
# $3 | |
# key | |
# $5 | |
# value | |
# $4 | |
# key1 | |
# $6 | |
# value1 | |
# $ | |
function redis_p() { | |
declare ARR=(${@:-$(</dev/stdin)}) | |
OUTPUT="*${#ARR[@]}\r\n" | |
for a in "${ARR[@]}"; do | |
OUTPUT+="\$${#a}\r\n${a}\r\n" | |
done | |
echo -ne $"${OUTPUT}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment