Created
August 19, 2019 18:59
-
-
Save jwmickey/36f6d41028351a171af81870387314a3 to your computer and use it in GitHub Desktop.
Generate Redis Protocol
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
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