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

Function setupNotificationHooks

maintnotifications/e2e/notiftracker_test.go:550–590  ·  view source on GitHub ↗

setupNotificationHooks adds multiple notification hooks to a regular client nolint:unused // Used in test files

(client redis.UniversalClient, hooks ...maintnotifications.NotificationHook)

Source from the content-addressed store, hash-verified

548//
549//nolint:unused // Used in test files
550func setupNotificationHooks(client redis.UniversalClient, hooks ...maintnotifications.NotificationHook) {
551 // Try to get manager from the client
552 var manager *maintnotifications.Manager
553
554 // Check if it's a regular client
555 if regularClient, ok := client.(*redis.Client); ok {
556 manager = regularClient.GetMaintNotificationsManager()
557 }
558
559 // Check if it's a cluster client
560 if clusterClient, ok := client.(*redis.ClusterClient); ok {
561 // For cluster clients, add hooks to all shards
562 _ = clusterClient.ForEachShard(context.Background(), func(ctx context.Context, nodeClient *redis.Client) error {
563 nodeManager := nodeClient.GetMaintNotificationsManager()
564 if nodeManager != nil {
565 for _, hook := range hooks {
566 nodeManager.AddNotificationHook(hook)
567 }
568 }
569 return nil
570 })
571
572 // Also add hooks to new nodes
573 clusterClient.OnNewNode(func(nodeClient *redis.Client) {
574 nodeManager := nodeClient.GetMaintNotificationsManager()
575 if nodeManager != nil {
576 for _, hook := range hooks {
577 nodeManager.AddNotificationHook(hook)
578 }
579 }
580 })
581 return
582 }
583
584 // For regular clients, add hooks directly
585 if manager != nil {
586 for _, hook := range hooks {
587 manager.AddNotificationHook(hook)
588 }
589 }
590}

Calls 4

AddNotificationHookMethod · 0.95
ForEachShardMethod · 0.45
OnNewNodeMethod · 0.45

Tested by

no test coverage detected