1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

fix: initialize push notification processor in SentinelClient

- Add push processor initialization to NewSentinelClient to prevent nil pointer dereference
- Add GetPushNotificationProcessor and RegisterPushNotificationHandler methods to SentinelClient
- Use VoidPushNotificationProcessor for Sentinel (typically doesn't need push notifications)
- Ensure consistent behavior across all client types that inherit from baseClient

This fixes the panic that was occurring in Sentinel contexts where the pushProcessor
field was nil, causing segmentation violations when processing commands.
This commit is contained in:
Nedyalko Dyakov
2025-06-27 01:44:38 +03:00
parent 8006fab753
commit d1d4529abf

View File

@ -492,6 +492,14 @@ func NewSentinelClient(opt *Options) *SentinelClient {
},
}
// Initialize push notification processor to prevent nil pointer dereference
if opt.PushNotificationProcessor != nil {
c.pushProcessor = opt.PushNotificationProcessor
} else {
// Create void processor for Sentinel (typically doesn't need push notifications)
c.pushProcessor = NewVoidPushNotificationProcessor()
}
c.initHooks(hooks{
dial: c.baseClient.dial,
process: c.baseClient.process,
@ -501,6 +509,18 @@ func NewSentinelClient(opt *Options) *SentinelClient {
return c
}
// GetPushNotificationProcessor returns the push notification processor.
func (c *SentinelClient) GetPushNotificationProcessor() PushNotificationProcessorInterface {
return c.pushProcessor
}
// RegisterPushNotificationHandler registers a handler for a specific push notification name.
// Returns an error if a handler is already registered for this push notification name.
// If protected is true, the handler cannot be unregistered.
func (c *SentinelClient) RegisterPushNotificationHandler(pushNotificationName string, handler PushNotificationHandler, protected bool) error {
return c.pushProcessor.RegisterHandler(pushNotificationName, handler, protected)
}
func (c *SentinelClient) Process(ctx context.Context, cmd Cmder) error {
err := c.processHook(ctx, cmd)
cmd.SetErr(err)