Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support set hooks option in new client API #2752

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ type Options struct {

// Disable set-lib on connect. Default is false.
DisableIndentity bool

// Hooks are initial hooks in options like AddHook.
Hooks []Hook

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Hooks array should be validated during initialization to ensure that invalid or nil hooks are not added. This can help prevent runtime issues and maintain the integrity of the client setup.

}

func (opt *Options) init() {
Expand Down
5 changes: 5 additions & 0 deletions osscluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type ClusterOptions struct {

TLSConfig *tls.Config
DisableIndentity bool // Disable set-lib on connect. Default is false.
Hooks []Hook
}

func (opt *ClusterOptions) init() {
Expand Down Expand Up @@ -871,6 +872,10 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
txPipeline: c.processTxPipeline,
})

for _, hook := range opt.Hooks {
c.AddHook(hook)
}

return c
}

Expand Down
4 changes: 4 additions & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ func newConn(opt *Options, connPool pool.Pooler) *Conn {
txPipeline: c.baseClient.processTxPipeline,
})

for _, hook := range opt.Hooks {
c.AddHook(hook)
}

return &c
}

Expand Down
4 changes: 4 additions & 0 deletions sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ func NewSentinelClient(opt *Options) *SentinelClient {
})
c.connPool = newConnPool(opt, c.dialHook)

for _, hook := range opt.Hooks {
c.AddHook(hook)
}

return c
}

Expand Down
Loading