Skip to content

Commit

Permalink
fix: Keep parent hooks when creating new connection.
Browse files Browse the repository at this point in the history
When creating a new connection from a client, uses the parent hooks as a
base, to ensure mocking is consistent.
  • Loading branch information
Michael Kuc committed Aug 22, 2023
1 parent c3098d5 commit 52f0ac0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
}

connPool := pool.NewSingleConnPool(c.connPool, cn)
conn := newConn(c.opt, connPool)
conn := newConn(c.opt, connPool, hooksMixin{})

var auth bool
protocol := c.opt.Protocol
Expand Down Expand Up @@ -636,7 +636,7 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
}

func (c *Client) Conn() *Conn {
return newConn(c.opt, pool.NewStickyConnPool(c.connPool))
return newConn(c.opt, pool.NewStickyConnPool(c.connPool), c.hooksMixin)
}

// Do create a Cmd from the args and processes the cmd.
Expand Down Expand Up @@ -772,7 +772,7 @@ type Conn struct {
hooksMixin
}

func newConn(opt *Options, connPool pool.Pooler) *Conn {
func newConn(opt *Options, connPool pool.Pooler, parentHooks hooksMixin) *Conn {
c := Conn{
baseClient: baseClient{
opt: opt,
Expand All @@ -782,6 +782,7 @@ func newConn(opt *Options, connPool pool.Pooler) *Conn {

c.cmdable = c.Process
c.statefulCmdable = c.Process
c.hooksMixin = parentHooks
c.initHooks(hooks{
dial: c.baseClient.dial,
process: c.baseClient.process,
Expand Down

0 comments on commit 52f0ac0

Please sign in to comment.