From d2e99845294796e93790ba23807832dd4911253c Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Fri, 8 Aug 2014 13:45:24 +0200 Subject: [PATCH] Recieve larger bulk strings than 4k from redis client. --- connection.go | 2 +- parser.go | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/connection.go b/connection.go index b62f426..1d2b116 100644 --- a/connection.go +++ b/connection.go @@ -39,7 +39,7 @@ func (c *Connection) Run() { c.conn.Close() }() rce := NewRedisCommandExecutor(c) - r := bufio.NewReader(c.conn) + r := bufio.NewReaderSize(c.conn, 8*1024) parser := NewRedisParser(r, rce) parser.Parse() log.Println("client disconnected") diff --git a/parser.go b/parser.go index 76ef322..7b8dee2 100644 --- a/parser.go +++ b/parser.go @@ -93,14 +93,17 @@ func (rp *RedisParser) bulkString(line []byte) bool { return rp.consumer.ConsumeBulkString([]byte{}) default: data := make([]byte, i, i) - var n int - if n, err = rp.reader.Read(data); err != nil { - return rp.consumer.ConsumeError(err) + for rest := i; rest > 0; { + var n int + if n, err = rp.reader.Read(data[i-rest : i]); err != nil { + return rp.consumer.ConsumeError(err) + } + rest -= int64(n) } if _, err = rp.reader.ReadBytes('\n'); err != nil { return rp.consumer.ConsumeError(err) } - return rp.consumer.ConsumeBulkString(data[0:n]) + return rp.consumer.ConsumeBulkString(data) } }