Skip to content

feat(Redis): Add connect/disconnect/error notifications to Client#5104

Merged
matejk merged 2 commits intomainfrom
feature/5058-redis-notifications
Dec 18, 2025
Merged

feat(Redis): Add connect/disconnect/error notifications to Client#5104
matejk merged 2 commits intomainfrom
feature/5058-redis-notifications

Conversation

@matejk
Copy link
Copy Markdown
Contributor

@matejk matejk commented Dec 17, 2025

Closes #5058

Summary

Adds event notification support to Poco::Redis::Client for connect, disconnect, and error events. This enables Node.js-style event handling for Redis client state changes.

New Components

  • RedisNotification - Base notification class
  • RedisConnectNotification - Fired on successful connection
  • RedisDisconnectNotification - Fired on disconnect
  • RedisErrorNotification - Fired on connection errors

Usage

auto pNC = client.notificationCenter();
NObserver<MyClass, RedisConnectNotification> obs(*this, &MyClass::onConnect);
pNC->addObserver(obs);
client.connect("localhost", 6379);  // Fires RedisConnectNotification

Original Implementation

Based on commits from devs/macchina.io repository:

  • d1ea231 - Initial notification support with AsyncNotificationCenter member
  • 18e06d3 - Lazy notification center creation with static std::once_flag
  • 3f63e1a - Changed to std::atomic<std::shared_ptr<AsyncNotificationCenter>>

Differences from Original

Aspect Original This PR
std::once_flag Static local variable Member variable
C++20 atomic shared_ptr Assumes available Conditional compilation
<mutex> include Not shown Added
Test counters int std::atomic<int> (thread-safe)
Member initialization Constructor init-list In-class initializers

C++20 Feature Detection

Added POCO_REDIS_HAVE_ATOMIC_SHARED_PTR macro to conditionally use std::atomic<std::shared_ptr<T>> when available, falling back to std::atomic<T*> otherwise. This ensures compatibility with compilers that don't yet support the C++20 atomic shared_ptr specialization.

Test plan

  • NotificationTest::testRedisNotifications - Basic notification creation
  • NotificationTest::testAsyncNotificationCenter - Async notification delivery
  • NotificationTest::testClientNotifications - Client integration
  • Build passes on macOS with clang (C++20 without atomic shared_ptr support)

Co-Authored-By: Alex Fabijanic <alex@pocoproject.org>
@matejk matejk requested a review from aleks-f December 17, 2025 17:23
@matejk matejk merged commit b44576a into main Dec 18, 2025
86 checks passed
@aleks-f aleks-f deleted the feature/5058-redis-notifications branch December 21, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add event notifications to Redis

2 participants