mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
feat: add GetHandler method and improve push notification API encapsulation
- Add GetHandler() method to PushNotificationProcessorInterface for better encapsulation - Add GetPushNotificationHandler() convenience method to Client and SentinelClient - Remove HasHandlers() check from ProcessPendingNotifications to ensure notifications are always consumed - Use PushNotificationProcessorInterface in internal pool package for proper abstraction - Maintain GetRegistry() for backward compatibility and testing - Update pubsub to use GetHandler() instead of GetRegistry() for cleaner code Benefits: - Better API encapsulation - no need to expose entire registry - Cleaner interface - direct access to specific handlers - Always consume push notifications from reader regardless of handler presence - Proper abstraction in internal pool package - Backward compatibility maintained - Consistent behavior across all processor types
This commit is contained in:
@ -28,9 +28,7 @@ func TestPushNotificationRegistry(t *testing.T) {
|
||||
registry := redis.NewPushNotificationRegistry()
|
||||
|
||||
// Test initial state
|
||||
if registry.HasHandlers() {
|
||||
t.Error("Registry should not have handlers initially")
|
||||
}
|
||||
// Registry starts empty (no need to check HasHandlers anymore)
|
||||
|
||||
commands := registry.GetRegisteredPushNotificationNames()
|
||||
if len(commands) != 0 {
|
||||
@ -49,10 +47,7 @@ func TestPushNotificationRegistry(t *testing.T) {
|
||||
t.Fatalf("Failed to register handler: %v", err)
|
||||
}
|
||||
|
||||
if !registry.HasHandlers() {
|
||||
t.Error("Registry should have handlers after registration")
|
||||
}
|
||||
|
||||
// Verify handler was registered by checking registered names
|
||||
commands = registry.GetRegisteredPushNotificationNames()
|
||||
if len(commands) != 1 || commands[0] != "TEST_COMMAND" {
|
||||
t.Errorf("Expected ['TEST_COMMAND'], got %v", commands)
|
||||
@ -803,7 +798,6 @@ func TestPushNotificationRegistryConcurrency(t *testing.T) {
|
||||
registry.HandleNotification(context.Background(), notification)
|
||||
|
||||
// Check registry state
|
||||
registry.HasHandlers()
|
||||
registry.GetRegisteredPushNotificationNames()
|
||||
}
|
||||
}(i)
|
||||
@ -815,10 +809,6 @@ func TestPushNotificationRegistryConcurrency(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify registry is still functional
|
||||
if !registry.HasHandlers() {
|
||||
t.Error("Registry should have handlers after concurrent operations")
|
||||
}
|
||||
|
||||
commands := registry.GetRegisteredPushNotificationNames()
|
||||
if len(commands) == 0 {
|
||||
t.Error("Registry should have registered commands after concurrent operations")
|
||||
|
Reference in New Issue
Block a user