Skip to content

Commit

Permalink
Fix slice grow in readN.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 14, 2016
1 parent 4665ad8 commit 672fb9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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))
})

Expand Down
1 change: 1 addition & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 672fb9b

Please sign in to comment.