Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
taytzehao committed Jul 20, 2023
1 parent 31ba855 commit 7575c17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
clone := *c
clone.baseClient = c.baseClient.withTimeout(timeout)
clone.init()
clone.connPool = newConnPool(clone.baseClient.opt, clone.dialHook)
return &clone
}

Expand Down
17 changes: 17 additions & 0 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ var _ = Describe("Client", func() {

err = client.Ping(ctx).Err()
Expect(err).NotTo(HaveOccurred())

//check withTimeout supports the addition of dialHook
var res []string
client.AddHook(&hook{
dialHook: func(hook redis.DialHook) redis.DialHook {
return func(ctx context.Context, network, addr string) (n net.Conn, e error) {
res = append(res, "dial-hook-start")
n, e = hook(ctx, network, addr)
return
}
},
})
err = client.Ping(ctx).Err()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]string{
"dial-hook-start",
}))
})

It("should ping", func() {
Expand Down

0 comments on commit 7575c17

Please sign in to comment.