NewRing returns a Redis Ring client to the Redis Server specified by RingOptions. Passing nil RingOptions will cause a panic.
(opt *RingOptions)
| 601 | // NewRing returns a Redis Ring client to the Redis Server specified by RingOptions. |
| 602 | // Passing nil RingOptions will cause a panic. |
| 603 | func 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 | |
| 635 | func (c *Ring) SetAddrs(addrs map[string]string) { |
| 636 | c.sharding.SetAddrs(addrs) |