support nil array

master
Jordan Orelli 11 years ago
parent fdac1f52ee
commit a73b957f1a

@ -101,9 +101,13 @@ func readBulkString(prefix []byte, r io.Reader) (value, error) {
return nil, fmt.Errorf("unable to read bulkstring in redis protocol: bad prefix: %v", err)
}
if n == -1 {
switch {
case n == -1:
return nil, nil
case n < 0:
return nil, fmt.Errorf("redis protocol error: illegal bulk string of negative length %d", n)
}
n += 2
b := make([]byte, n)
n_read, err := r.Read(b)
@ -135,6 +139,13 @@ func readArray(prefix []byte, r *bufio.Reader) (value, error) {
return nil, fmt.Errorf("unable to read array in redis protocol: bad prefix: %v", err)
}
switch {
case n == -1:
return nil, nil
case n < 0:
return nil, fmt.Errorf("redis protocol error: illegal array of negative length %d", n)
}
a := make(Array, n)
for i := int64(0); i < n; i++ {
v, err := readValue(r)

@ -79,6 +79,7 @@ var valueTests = []valueTest{
{":9223372036854775807\r\n+extra\r\n", Integer(9223372036854775807)}, // int64 max
{":-9223372036854775808\r\n+extra\r\n", Integer(-9223372036854775808)}, // int64 min
{"*-1\r\n", nil}, // nil array
{"*0\r\n", Array{}}, // is this a thing? I have no idea.
{"*1\r\n+hello\r\n", Array{String("hello")}},
{"*2\r\n+one\r\n+two", Array{String("one"), String("two")}},

Loading…
Cancel
Save