Merge pull request #279 from go-redis/fix/readn-slice-grow

Fix slice grow in readN.
This commit is contained in:
Vladimir Mihailenco 2016-03-14 12:46:01 +02:00
commit 50b2689809
2 changed files with 12 additions and 2 deletions

View File

@ -15,10 +15,14 @@ import (
var _ = Describe("Command", func() { var _ = Describe("Command", func() {
var client *redis.Client var client *redis.Client
BeforeEach(func() { connect := func() *redis.Client {
client = redis.NewClient(&redis.Options{ return redis.NewClient(&redis.Options{
Addr: redisAddr, Addr: redisAddr,
}) })
}
BeforeEach(func() {
client = connect()
}) })
AfterEach(func() { AfterEach(func() {
@ -63,8 +67,13 @@ var _ = Describe("Command", func() {
Expect(set.Err()).NotTo(HaveOccurred()) Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK")) Expect(set.Val()).To(Equal("OK"))
// Reconnect to get new connection.
Expect(client.Close()).To(BeNil())
client = connect()
get := client.Get("key") get := client.Get("key")
Expect(get.Err()).NotTo(HaveOccurred()) Expect(get.Err()).NotTo(HaveOccurred())
Expect(len(get.Val())).To(Equal(len(val)))
Expect(get.Val()).To(Equal(val)) Expect(get.Val()).To(Equal(val))
}) })

View File

@ -247,6 +247,7 @@ func isNilReply(b []byte) bool {
func readN(cn *pool.Conn, n int) ([]byte, error) { func readN(cn *pool.Conn, n int) ([]byte, error) {
if d := n - cap(cn.Buf); d > 0 { if d := n - cap(cn.Buf); d > 0 {
cn.Buf = cn.Buf[:cap(cn.Buf)]
cn.Buf = append(cn.Buf, make([]byte, d)...) cn.Buf = append(cn.Buf, make([]byte, d)...)
} else { } else {
cn.Buf = cn.Buf[:n] cn.Buf = cn.Buf[:n]