@@ -26,6 +26,7 @@ type HAConfig struct {
26
26
Password string // the password of the master
27
27
ReadonlyPassword string // the passsword of slaves
28
28
Options * redis.Options // redis options
29
+ Hooks []redis.Hook // optional list of redis hooks
29
30
PollType int // the slave polling type
30
31
31
32
AutoEjectHost bool // eject the failure host or not
@@ -85,7 +86,7 @@ func NewHAConnFactory(cfg *HAConfig) (*HAConnFactory, error) {
85
86
options .Addr = cfg .Master
86
87
options .Password = cfg .Password
87
88
88
- factory .master = newClient (redis .NewClient (& options ), 0 )
89
+ factory .master = newClient (redis .NewClient (& options ), 0 , cfg . Hooks )
89
90
factory .slaves = newClientPool (cfg )
90
91
return factory , nil
91
92
}
@@ -150,14 +151,17 @@ func (cfg *HAConfig) init() error {
150
151
return nil
151
152
}
152
153
153
- func newClient (redisCli * redis.Client , weight int64 ) * client {
154
+ func newClient (redisCli * redis.Client , weight int64 , hooks []redis. Hook ) * client {
154
155
c := & client {
155
156
redisCli : redisCli ,
156
157
weight : weight ,
157
158
158
159
failureCount : 0 ,
159
160
lastEjectTime : 0 ,
160
161
}
162
+ for _ , hook := range hooks {
163
+ c .redisCli .AddHook (hook )
164
+ }
161
165
return c
162
166
}
163
167
@@ -193,7 +197,7 @@ func newClientPool(cfg *HAConfig) *clientPool {
193
197
slaveOptions .Addr = slave
194
198
slaveOptions .Password = slavePassword
195
199
redisCli := redis .NewClient (& slaveOptions )
196
- cli := newClient (redisCli , cfg .weights [i ])
200
+ cli := newClient (redisCli , cfg .weights [i ], cfg . Hooks )
197
201
if cfg .AutoEjectHost && len (cfg .Slaves ) > 1 {
198
202
redisCli .AddHook (newFailureHook (cli ))
199
203
}
0 commit comments