mirror of
https://github.com/redis/go-redis.git
synced 2025-07-29 17:41:15 +03:00
feat: add VoidPushNotificationProcessor for disabled push notifications
- Add VoidPushNotificationProcessor that reads and discards push notifications - Create PushNotificationProcessorInterface for consistent behavior - Always provide a processor (real or void) instead of nil - VoidPushNotificationProcessor properly cleans RESP3 push notifications from buffer - Remove all nil checks throughout codebase for cleaner, safer code - Update tests to expect VoidPushNotificationProcessor when disabled Benefits: - Eliminates nil pointer risks throughout the codebase - Follows null object pattern for safer operation - Properly handles RESP3 push notifications even when disabled - Consistent interface regardless of push notification settings - Cleaner code without defensive nil checks everywhere
This commit is contained in:
23
pubsub.go
23
pubsub.go
@ -40,7 +40,7 @@ type PubSub struct {
|
||||
allCh *channel
|
||||
|
||||
// Push notification processor for handling generic push notifications
|
||||
pushProcessor *PushNotificationProcessor
|
||||
pushProcessor PushNotificationProcessorInterface
|
||||
}
|
||||
|
||||
func (c *PubSub) init() {
|
||||
@ -49,7 +49,7 @@ func (c *PubSub) init() {
|
||||
|
||||
// SetPushNotificationProcessor sets the push notification processor for handling
|
||||
// generic push notifications received on this PubSub connection.
|
||||
func (c *PubSub) SetPushNotificationProcessor(processor *PushNotificationProcessor) {
|
||||
func (c *PubSub) SetPushNotificationProcessor(processor PushNotificationProcessorInterface) {
|
||||
c.pushProcessor = processor
|
||||
}
|
||||
|
||||
@ -435,15 +435,18 @@ func (c *PubSub) newMessage(reply interface{}) (interface{}, error) {
|
||||
}, nil
|
||||
default:
|
||||
// Try to handle as generic push notification
|
||||
if c.pushProcessor != nil && c.pushProcessor.IsEnabled() {
|
||||
if c.pushProcessor.IsEnabled() {
|
||||
ctx := c.getContext()
|
||||
handled := c.pushProcessor.GetRegistry().HandleNotification(ctx, reply)
|
||||
if handled {
|
||||
// Return a special message type to indicate it was handled
|
||||
return &PushNotificationMessage{
|
||||
Command: kind,
|
||||
Args: reply[1:],
|
||||
}, nil
|
||||
registry := c.pushProcessor.GetRegistry()
|
||||
if registry != nil {
|
||||
handled := registry.HandleNotification(ctx, reply)
|
||||
if handled {
|
||||
// Return a special message type to indicate it was handled
|
||||
return &PushNotificationMessage{
|
||||
Command: kind,
|
||||
Args: reply[1:],
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("redis: unsupported pubsub message: %q", kind)
|
||||
|
Reference in New Issue
Block a user