Skip to content

Instantly share code, notes, and snippets.

@mweibel
Last active December 17, 2020 05:14
Show Gist options
  • Save mweibel/7464993 to your computer and use it in GitHub Desktop.
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.
#!/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