mirror of
https://github.com/redis/go-redis.git
synced 2025-07-18 00:20:57 +03:00
feat: add pub/sub message filtering to push notification processor
- Add isPubSubMessage() function to identify pub/sub message types - Filter out pub/sub messages in ProcessPendingNotifications - Allow pub/sub system to handle its own messages without interference - Process only cluster/system push notifications (MOVING, MIGRATING, etc.) - Add comprehensive test coverage for filtering logic Pub/sub message types filtered: - message (regular pub/sub) - pmessage (pattern pub/sub) - subscribe/unsubscribe (subscription management) - psubscribe/punsubscribe (pattern subscription management) - smessage (sharded pub/sub, Redis 7.0+) Benefits: - Clear separation of concerns between pub/sub and push notifications - Prevents interference between the two messaging systems - Ensures pub/sub messages reach their intended handlers - Eliminates message loss due to incorrect interception - Improved system reliability and performance - Better resource utilization and message flow Implementation: - Efficient O(1) switch statement for message type lookup - Case-sensitive matching for precise filtering - Early return to skip unnecessary processing - Maintains processing of other notifications in same batch - Applied to all processing points (WithReader, Pool.Put, isHealthyConn) Test coverage: - TestIsPubSubMessage - Function correctness and edge cases - TestPubSubFiltering - End-to-end integration testing - Mixed message scenarios and handler verification
This commit is contained in:
@ -39,11 +39,7 @@ func (r *PushNotificationRegistry) UnregisterHandler(pushNotificationName string
|
||||
|
||||
// GetHandler returns the handler for a specific push notification name.
|
||||
func (r *PushNotificationRegistry) GetHandler(pushNotificationName string) PushNotificationHandler {
|
||||
handler := r.registry.GetHandler(pushNotificationName)
|
||||
if handler == nil {
|
||||
return nil
|
||||
}
|
||||
return handler
|
||||
return r.registry.GetHandler(pushNotificationName)
|
||||
}
|
||||
|
||||
// GetRegisteredPushNotificationNames returns a list of all registered push notification names.
|
||||
@ -51,8 +47,6 @@ func (r *PushNotificationRegistry) GetRegisteredPushNotificationNames() []string
|
||||
return r.registry.GetRegisteredPushNotificationNames()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PushNotificationProcessor handles push notifications with a registry of handlers.
|
||||
type PushNotificationProcessor struct {
|
||||
processor *pushnotif.Processor
|
||||
@ -67,12 +61,7 @@ func NewPushNotificationProcessor() *PushNotificationProcessor {
|
||||
|
||||
// GetHandler returns the handler for a specific push notification name.
|
||||
func (p *PushNotificationProcessor) GetHandler(pushNotificationName string) PushNotificationHandler {
|
||||
handler := p.processor.GetHandler(pushNotificationName)
|
||||
if handler == nil {
|
||||
return nil
|
||||
}
|
||||
// The handler is already a PushNotificationHandler since we store it directly
|
||||
return handler.(PushNotificationHandler)
|
||||
return p.processor.GetHandler(pushNotificationName)
|
||||
}
|
||||
|
||||
// RegisterHandler registers a handler for a specific push notification name.
|
||||
@ -90,8 +79,6 @@ func (p *PushNotificationProcessor) ProcessPendingNotifications(ctx context.Cont
|
||||
return p.processor.ProcessPendingNotifications(ctx, rd)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// VoidPushNotificationProcessor discards all push notifications without processing them.
|
||||
type VoidPushNotificationProcessor struct {
|
||||
processor *pushnotif.VoidProcessor
|
||||
@ -119,8 +106,6 @@ func (v *VoidPushNotificationProcessor) ProcessPendingNotifications(ctx context.
|
||||
return v.processor.ProcessPendingNotifications(ctx, rd)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Redis Cluster push notification names
|
||||
const (
|
||||
PushNotificationMoving = "MOVING"
|
||||
|
Reference in New Issue
Block a user