mirror of https://github.com/go-redis/redis.git
Fixes issue where a buffer larger than 4096
bytes cannot be read
This commit is contained in:
parent
b965d69fc9
commit
97bbed8a92
|
@ -55,10 +55,13 @@ func (r *Reader) Reset(rd io.Reader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) ReadLine() ([]byte, error) {
|
func (r *Reader) ReadLine() ([]byte, error) {
|
||||||
line, err := r.readLine()
|
line, err := r.rd.ReadBytes('\n')
|
||||||
if err != nil {
|
if err != nil && err != io.EOF {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if len(line) == 0 {
|
||||||
|
return nil, fmt.Errorf("redis: reply is empty")
|
||||||
|
}
|
||||||
if isNilReply(line) {
|
if isNilReply(line) {
|
||||||
return nil, Nil
|
return nil, Nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,19 @@ func BenchmarkReader_ParseReply_Slice(b *testing.B) {
|
||||||
benchmarkParseReply(b, "*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", multiBulkParse, false)
|
benchmarkParseReply(b, "*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", multiBulkParse, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReader_ReadLine(t *testing.T) {
|
||||||
|
original := bytes.Repeat([]byte("a"), 8192)
|
||||||
|
r := proto.NewReader(bytes.NewReader(original))
|
||||||
|
read, err := r.ReadLine()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Should be able to read the full buffer: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if bytes.Compare(read, original) != 0 {
|
||||||
|
t.Errorf("Values must be equal: %q", read)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func benchmarkParseReply(b *testing.B, reply string, m proto.MultiBulkParse, wanterr bool) {
|
func benchmarkParseReply(b *testing.B, reply string, m proto.MultiBulkParse, wanterr bool) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
|
Loading…
Reference in New Issue