diff --git a/redis.go b/redis.go index e0159294d..b70e4fe06 100644 --- a/redis.go +++ b/redis.go @@ -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 } diff --git a/redis_test.go b/redis_test.go index 7d9bf1cef..713b74409 100644 --- a/redis_test.go +++ b/redis_test.go @@ -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() {