Skip to content

Commit 79b3d02

Browse files
committed
Ignore blank lines on readResposne
1 parent 01a0bcf commit 79b3d02

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

redis-dump.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ func dump_db(port int, db int, output io.Writer) {
1919
client.Db = db
2020
}
2121

22+
fmt.Fprintf(output, "FLUSHDB\r\n")
23+
2224
keys, err := client.Keys("*")
2325

2426
if err != nil {
2527
println("Redis-dump failed", err.String())
2628
return
2729
}
2830

29-
fmt.Fprintf(output, "FLUSHDB\r\n")
3031

3132
for _, key := range (keys) {
3233
typ, _ := client.Type(key)

redis.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,22 @@ func readBulk(reader *bufio.Reader, head string) ([]byte, os.Error) {
6767
}
6868

6969
func readResponse(reader *bufio.Reader) (interface{}, os.Error) {
70-
line, err := reader.ReadString('\n')
7170

72-
if err != nil {
73-
return nil, err
74-
}
71+
var line string
72+
var err os.Error
7573

74+
//read until the first non-whitespace line
75+
for {
76+
line, err = reader.ReadString('\n')
77+
if len(line) == 0 || err != nil {
78+
return nil, err
79+
}
80+
line = strings.TrimSpace(line)
81+
if len(line) > 0 {
82+
break
83+
}
84+
}
85+
7686
if line[0] == '+' {
7787
return strings.TrimSpace(line[1:]), nil
7888
}
@@ -176,7 +186,6 @@ func (client *Client) sendCommand(cmd string) (data interface{}, err os.Error) {
176186
data, err = client.rawSend(c, strings.Bytes(cmd))
177187

178188
if err == os.EOF {
179-
println("got eof")
180189
c, err = client.openConnection()
181190
if err != nil {
182191
goto End

0 commit comments

Comments
 (0)