Skip to content

Instantly share code, notes, and snippets.

@jwmickey
Created August 19, 2019 18:59
Show Gist options
  • Save jwmickey/36f6d41028351a171af81870387314a3 to your computer and use it in GitHub Desktop.
Save jwmickey/36f6d41028351a171af81870387314a3 to your computer and use it in GitHub Desktop.
Generate Redis Protocol
func genRedisProto(c chan string, cmd ...string) {
proto := fmt.Sprintf("*%v\r\n", len(cmd))
for _, word := range cmd {
proto = proto + fmt.Sprintf("$%v\r\n", len(word))
proto = proto + word + "\r\n"
}
c <- proto
}
func main() {
f, err := os.Create("raw.txt")
check(err)
defer f.Close()
w := bufio.NewWriter(f)
c := make(chan string)
go genRedisProto(c,
"SET",
"HELLO"
"WORLD")
fmt.Fprint(w, <-c)
w.Flush()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment