diff --git a/options.go b/options.go index 449a92521..3207ad772 100644 --- a/options.go +++ b/options.go @@ -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 } func (opt *Options) init() { diff --git a/osscluster.go b/osscluster.go index b8a82d9bc..14b7c23ef 100644 --- a/osscluster.go +++ b/osscluster.go @@ -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() { @@ -871,6 +872,10 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient { txPipeline: c.processTxPipeline, }) + for _, hook := range opt.Hooks { + c.AddHook(hook) + } + return c } diff --git a/redis.go b/redis.go index 9792af760..a0d01730d 100644 --- a/redis.go +++ b/redis.go @@ -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 } diff --git a/sentinel.go b/sentinel.go index 31ea3c77a..589822a4d 100644 --- a/sentinel.go +++ b/sentinel.go @@ -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 }