MCPcopy
hub / github.com/redis/go-redis / NewRing

Function NewRing

ring.go:603–633  ·  view source on GitHub ↗

NewRing returns a Redis Ring client to the Redis Server specified by RingOptions. Passing nil RingOptions will cause a panic.

(opt *RingOptions)

Source from the content-addressed store, hash-verified

601// NewRing returns a Redis Ring client to the Redis Server specified by RingOptions.
602// Passing nil RingOptions will cause a panic.
603func NewRing(opt *RingOptions) *Ring {
604 if opt == nil {
605 panic("redis: NewRing nil options")
606 }
607 opt.init()
608
609 hbCtx, hbCancel := context.WithCancel(context.Background())
610
611 ring := Ring{
612 opt: opt,
613 sharding: newRingSharding(opt),
614 heartbeatCancelFn: hbCancel,
615 }
616
617 ring.cmdsInfoCache = newCmdsInfoCache(ring.cmdsInfo)
618 ring.cmdable = ring.Process
619
620 ring.initHooks(hooks{
621 process: ring.process,
622 pipeline: func(ctx context.Context, cmds []Cmder) error {
623 return ring.generalProcessPipeline(ctx, cmds, false)
624 },
625 txPipeline: func(ctx context.Context, cmds []Cmder) error {
626 return ring.generalProcessPipeline(ctx, cmds, true)
627 },
628 })
629
630 go ring.sharding.Heartbeat(hbCtx, opt.HeartbeatFrequency)
631
632 return &ring
633}
634
635func (c *Ring) SetAddrs(addrs map[string]string) {
636 c.sharding.SetAddrs(addrs)

Calls 6

newRingShardingFunction · 0.85
newCmdsInfoCacheFunction · 0.85
initHooksMethod · 0.80
HeartbeatMethod · 0.80
initMethod · 0.45