forked from mirror/redis
Add RingOptions.OnNewShard
This commit is contained in:
parent
472322938c
commit
0c4c236793
|
@ -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 {
|
||||
|
|
18
ring.go
18
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue