1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-15 12:41:41 +03:00

Optimize reading big values

This commit is contained in:
Vladimir Mihailenco
2018-08-16 13:25:19 +03:00
parent 929bfb147c
commit 00de347403
6 changed files with 134 additions and 147 deletions

View File

@ -6,42 +6,12 @@ import (
"testing"
"github.com/go-redis/redis/internal/proto"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func newReader(s string) proto.Reader {
return proto.NewReader(proto.NewElasticBufReader(strings.NewReader(s)))
}
var _ = Describe("Reader", func() {
It("should read n bytes", func() {
data, err := newReader("ABCDEFGHIJKLMNO").ReadN(10)
Expect(err).NotTo(HaveOccurred())
Expect(len(data)).To(Equal(10))
Expect(string(data)).To(Equal("ABCDEFGHIJ"))
data, err = newReader(strings.Repeat("x", 8192)).ReadN(6000)
Expect(err).NotTo(HaveOccurred())
Expect(len(data)).To(Equal(6000))
})
It("should read lines", func() {
r := newReader("$5\r\nhello\r\n")
data, err := r.ReadLine()
Expect(err).NotTo(HaveOccurred())
Expect(string(data)).To(Equal("$5"))
data, err = r.ReadLine()
Expect(err).NotTo(HaveOccurred())
Expect(string(data)).To(Equal("hello"))
})
})
func BenchmarkReader_ParseReply_Status(b *testing.B) {
benchmarkParseReply(b, "+OK\r\n", nil, false)
}