diff --git a/options.go b/options.go index d29526c..54c6fae 100644 --- a/options.go +++ b/options.go @@ -114,7 +114,7 @@ func (opt *Options) init() { if opt.TLSConfig == nil { return netDialer.DialContext(ctx, network, addr) } - return tls.DialWithDialer(netDialer, opt.Network, opt.Addr, opt.TLSConfig) + return tls.DialWithDialer(netDialer, network, addr, opt.TLSConfig) } } if opt.PoolSize == 0 { diff --git a/ring.go b/ring.go index 9a53d04..1c98191 100644 --- a/ring.go +++ b/ring.go @@ -56,6 +56,9 @@ type RingOptions struct { // See https://arxiv.org/abs/1406.2294 for reference HashReplicas int + // Optional hook that is called when a new shard is created. + OnNewShard func(*Client) + // Following options are copied from Options struct. OnConnect func(*Conn) error @@ -376,9 +379,8 @@ func NewRing(opt *RingOptions) *Ring { ring.cmdsInfoCache = newCmdsInfoCache(ring.cmdsInfo) for name, addr := range opt.Addrs { - clopt := opt.clientOptions(name) - clopt.Addr = addr - ring.shards.Add(name, NewClient(clopt)) + shard := newRingShard(opt, name, addr) + ring.shards.Add(name, shard) } go ring.shards.Heartbeat(opt.HeartbeatFrequency) @@ -386,6 +388,16 @@ func NewRing(opt *RingOptions) *Ring { return &ring } +func newRingShard(opt *RingOptions, name, addr string) *Client { + clopt := opt.clientOptions(name) + clopt.Addr = addr + shard := NewClient(clopt) + if opt.OnNewShard != nil { + opt.OnNewShard(shard) + } + return shard +} + func (c *Ring) init() { c.cmdable = c.Process }