mirror of
https://github.com/redis/go-redis.git
synced 2025-04-19 07:22:17 +03:00
Fix slice grow in readN.
This commit is contained in:
parent
4665ad860f
commit
672fb9bb97
@ -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))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -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]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user