diff --git a/command_test.go b/command_test.go index 1218724..088b178 100644 --- a/command_test.go +++ b/command_test.go @@ -15,10 +15,14 @@ import ( var _ = Describe("Command", func() { var client *redis.Client - BeforeEach(func() { - client = redis.NewClient(&redis.Options{ + connect := func() *redis.Client { + return redis.NewClient(&redis.Options{ Addr: redisAddr, }) + } + + BeforeEach(func() { + client = connect() }) AfterEach(func() { @@ -63,8 +67,13 @@ var _ = Describe("Command", func() { Expect(set.Err()).NotTo(HaveOccurred()) Expect(set.Val()).To(Equal("OK")) + // Reconnect to get new connection. + Expect(client.Close()).To(BeNil()) + client = connect() + get := client.Get("key") Expect(get.Err()).NotTo(HaveOccurred()) + Expect(len(get.Val())).To(Equal(len(val))) Expect(get.Val()).To(Equal(val)) }) diff --git a/parser.go b/parser.go index 2496f66..3d8742c 100644 --- a/parser.go +++ b/parser.go @@ -247,6 +247,7 @@ func isNilReply(b []byte) bool { func readN(cn *pool.Conn, n int) ([]byte, error) { if d := n - cap(cn.Buf); d > 0 { + cn.Buf = cn.Buf[:cap(cn.Buf)] cn.Buf = append(cn.Buf, make([]byte, d)...) } else { cn.Buf = cn.Buf[:n]