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

Function NewSentinelClient

sentinel.go:621–658  ·  view source on GitHub ↗

NewSentinelClient returns a Redis Sentinel client. Passing nil Options will cause a panic.

(opt *Options)

Source from the content-addressed store, hash-verified

619// NewSentinelClient returns a Redis Sentinel client.
620// Passing nil Options will cause a panic.
621func NewSentinelClient(opt *Options) *SentinelClient {
622 if opt == nil {
623 panic("redis: NewSentinelClient nil options")
624 }
625 opt.init()
626 c := &SentinelClient{
627 baseClient: &baseClient{
628 opt: opt,
629 onClose: &onCloseHooks{},
630 },
631 }
632
633 // Initialize push notification processor using shared helper
634 // Use void processor for Sentinel clients
635 c.pushProcessor = NewVoidPushNotificationProcessor()
636
637 c.initHooks(hooks{
638 dial: c.baseClient.dial,
639 process: c.baseClient.process,
640 })
641
642 // Generate unique pool names for metrics
643 uniqueID := generateUniqueID()
644 mainPoolName := opt.Addr + "_" + uniqueID
645 pubsubPoolName := opt.Addr + "_" + uniqueID + "_pubsub"
646
647 var err error
648 c.connPool, err = newConnPool(opt, c.dialHook, mainPoolName)
649 if err != nil {
650 panic(fmt.Errorf("redis: failed to create connection pool: %w", err))
651 }
652 c.pubSubPool, err = newPubSubPool(opt, c.dialHook, pubsubPoolName)
653 if err != nil {
654 panic(fmt.Errorf("redis: failed to create pubsub pool: %w", err))
655 }
656
657 return c
658}
659
660// GetPushNotificationHandler returns the handler for a specific push notification name.
661// Returns nil if no handler is registered for the given name.

Callers 2

MasterAddrMethod · 0.85
replicaAddrsMethod · 0.85

Calls 6

newConnPoolFunction · 0.85
newPubSubPoolFunction · 0.85
initHooksMethod · 0.80
generateUniqueIDFunction · 0.70
initMethod · 0.45

Tested by

no test coverage detected