mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
feat: enforce single handler per notification type
- Change PushNotificationRegistry to allow only one handler per command - RegisterHandler methods now return error if handler already exists - Update UnregisterHandler to remove handler by command only - Update all client methods to return errors for duplicate registrations - Update comprehensive test suite to verify single handler behavior - Add specific test for duplicate handler error scenarios This prevents handler conflicts and ensures predictable notification routing with clear error handling for registration conflicts.
This commit is contained in:
12
redis.go
12
redis.go
@ -814,10 +814,12 @@ func (c *Client) initializePushProcessor() {
|
||||
}
|
||||
|
||||
// RegisterPushNotificationHandler registers a handler for a specific push notification command.
|
||||
func (c *Client) RegisterPushNotificationHandler(command string, handler PushNotificationHandler) {
|
||||
// Returns an error if a handler is already registered for this command.
|
||||
func (c *Client) RegisterPushNotificationHandler(command string, handler PushNotificationHandler) error {
|
||||
if c.pushProcessor != nil {
|
||||
c.pushProcessor.RegisterHandler(command, handler)
|
||||
return c.pushProcessor.RegisterHandler(command, handler)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterGlobalPushNotificationHandler registers a handler that will receive all push notifications.
|
||||
@ -828,10 +830,12 @@ func (c *Client) RegisterGlobalPushNotificationHandler(handler PushNotificationH
|
||||
}
|
||||
|
||||
// RegisterPushNotificationHandlerFunc registers a function as a handler for a specific push notification command.
|
||||
func (c *Client) RegisterPushNotificationHandlerFunc(command string, handlerFunc func(ctx context.Context, notification []interface{}) bool) {
|
||||
// Returns an error if a handler is already registered for this command.
|
||||
func (c *Client) RegisterPushNotificationHandlerFunc(command string, handlerFunc func(ctx context.Context, notification []interface{}) bool) error {
|
||||
if c.pushProcessor != nil {
|
||||
c.pushProcessor.RegisterHandlerFunc(command, handlerFunc)
|
||||
return c.pushProcessor.RegisterHandlerFunc(command, handlerFunc)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterGlobalPushNotificationHandlerFunc registers a function as a global handler for all push notifications.
|
||||
|
Reference in New Issue
Block a user