Last active
December 17, 2020 05:14
-
-
Save mweibel/7464993 to your computer and use it in GitHub Desktop.
Redis protocol generator in bash according to http://redis.io/topics/mass-insert. Use e.g. with `./fixture.sh |redis-cli --pipe`.
Whitespaces within values are currently not supported.
This file contains 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
#!/bin/bash | |
# | |
# License: MIT | |
# Author: Michael Weibel | |
# | |
gen_redis_protocol() { | |
cmd=$1 | |
proto="" | |
proto+="*" | |
number_of_words=0 | |
byword="" | |
for word in $cmd | |
do | |
number_of_words=$[number_of_words+1] | |
byword+="$" | |
byword+=${#word} | |
byword+="\\r\\n" | |
byword+=$word | |
byword+="\\r\\n" | |
done | |
proto+=${number_of_words} | |
proto+="\\r\\n" | |
proto+=${byword} | |
printf $proto | |
} | |
gen_redis_protocol "SET mykey Hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment