Recieve larger bulk strings than 4k from redis client.

This commit is contained in:
Sascha L. Teichmann 2014-08-08 13:45:24 +02:00
parent 2e47262ce8
commit d2e9984529
2 changed files with 8 additions and 5 deletions

View File

@ -39,7 +39,7 @@ func (c *Connection) Run() {
c.conn.Close() c.conn.Close()
}() }()
rce := NewRedisCommandExecutor(c) rce := NewRedisCommandExecutor(c)
r := bufio.NewReader(c.conn) r := bufio.NewReaderSize(c.conn, 8*1024)
parser := NewRedisParser(r, rce) parser := NewRedisParser(r, rce)
parser.Parse() parser.Parse()
log.Println("client disconnected") log.Println("client disconnected")

View File

@ -93,14 +93,17 @@ func (rp *RedisParser) bulkString(line []byte) bool {
return rp.consumer.ConsumeBulkString([]byte{}) return rp.consumer.ConsumeBulkString([]byte{})
default: default:
data := make([]byte, i, i) data := make([]byte, i, i)
var n int for rest := i; rest > 0; {
if n, err = rp.reader.Read(data); err != nil { var n int
return rp.consumer.ConsumeError(err) 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 { if _, err = rp.reader.ReadBytes('\n'); err != nil {
return rp.consumer.ConsumeError(err) return rp.consumer.ConsumeError(err)
} }
return rp.consumer.ConsumeBulkString(data[0:n]) return rp.consumer.ConsumeBulkString(data)
} }
} }