Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,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
26 changes: 26 additions & 0 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,32 @@ var _ = Describe("Client", func() {

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

})

It("timeout should support dialHook", func() {

var res []string

client := redis.NewClient(&redis.Options{
Addr: redisAddr,
MaxRetries: 1,
})
client.WithTimeout(10 * time.Millisecond)
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 n, e
}
},
})
err := client.Ping(ctx).Err()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]string{
"dial-hook-start",
}))
})

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