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 {
5656 // See https://arxiv.org/abs/1406.2294 for reference
5757 HashReplicas int
5858
59+ // NewClient creates a shard client with provided name and options.
60+ NewClient func (name string , opt * Options ) * Client
61+
5962 // Optional hook that is called when a new shard is created.
6063 OnNewShard func (* Client )
6164
@@ -390,7 +393,12 @@ func NewRing(opt *RingOptions) *Ring {
390393func newRingShard (opt * RingOptions , name , addr string ) * Client {
391394 clopt := opt .clientOptions (name )
392395 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+ }
394402 if opt .OnNewShard != nil {
395403 opt .OnNewShard (shard )
396404 }
Original file line number Diff line number Diff line change @@ -196,6 +196,20 @@ var _ = Describe("Redis Ring", func() {
196196 })
197197 })
198198
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+
199213 It ("supports Process hook" , func () {
200214 err := ring .Ping ().Err ()
201215 Expect (err ).NotTo (HaveOccurred ())
You can’t perform that action at this time.
0 commit comments