Reading TCP connection between Redis-server by using bufio.Scanner
fmt.Fprintf(conn, "*3
$3
SET
$5
mykey
$7
Hello!!
")
scanner := bufio.NewScanner(conn)
for {
// fmt.Println("marker00")
if ok := scanner.Scan(); !ok {
// fmt.Println("marker01")
break
}
// fmt.Println("marker02")
fmt.Println(scanner.Text())
}
"+OK" comes as the result for first scanning, but the second scanning stops just in invoking Scan
method. (marker00 -> marker02 -> marker00 and no output any more)
Why does Scan
stop and how can I know the end of TCP response (without using bufio.Reader
)?