File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ type RingOptions struct {
56
56
// See https://arxiv.org/abs/1406.2294 for reference
57
57
HashReplicas int
58
58
59
+ // NewClient creates a shard client with provided name and options.
60
+ NewClient func (name string , opt * Options ) * Client
61
+
59
62
// Optional hook that is called when a new shard is created.
60
63
OnNewShard func (* Client )
61
64
@@ -390,7 +393,12 @@ func NewRing(opt *RingOptions) *Ring {
390
393
func newRingShard (opt * RingOptions , name , addr string ) * Client {
391
394
clopt := opt .clientOptions (name )
392
395
clopt .Addr = addr
393
- shard := NewClient (clopt )
396
+ var shard * Client
397
+ if opt .NewClient != nil {
398
+ shard = opt .NewClient (name , clopt )
399
+ } else {
400
+ shard = NewClient (clopt )
401
+ }
394
402
if opt .OnNewShard != nil {
395
403
opt .OnNewShard (shard )
396
404
}
Original file line number Diff line number Diff line change @@ -196,6 +196,20 @@ var _ = Describe("Redis Ring", func() {
196
196
})
197
197
})
198
198
199
+ Describe ("new client callback" , func () {
200
+ It ("can be initialized with a new client callback" , func () {
201
+ opts := redisRingOptions ()
202
+ opts .NewClient = func (name string , opt * redis.Options ) * redis.Client {
203
+ opt .Password = "password1"
204
+ return redis .NewClient (opt )
205
+ }
206
+ ring = redis .NewRing (opts )
207
+
208
+ err := ring .Ping ().Err ()
209
+ Expect (err ).To (MatchError ("ERR Client sent AUTH, but no password is set" ))
210
+ })
211
+ })
212
+
199
213
It ("supports Process hook" , func () {
200
214
err := ring .Ping ().Err ()
201
215
Expect (err ).NotTo (HaveOccurred ())
You can’t perform that action at this time.
0 commit comments