1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

feat: expand notification filtering to include streams, keyspace, and client tracking

- Rename isPubSubMessage to shouldSkipNotification for broader scope
- Add filtering for stream notifications (xread-from, xreadgroup-from)
- Add filtering for client tracking notifications (invalidate)
- Add filtering for keyspace notifications (expired, evicted, set, del, etc.)
- Add filtering for sharded pub/sub notifications (ssubscribe, sunsubscribe)
- Update comprehensive test coverage for all notification types

Notification types now filtered:
- Pub/Sub: message, pmessage, subscribe, unsubscribe, psubscribe, punsubscribe
- Sharded Pub/Sub: smessage, ssubscribe, sunsubscribe
- Streams: xread-from, xreadgroup-from
- Client tracking: invalidate
- Keyspace events: expired, evicted, set, del, rename, move, copy, restore, sort, flushdb, flushall

Benefits:
- Comprehensive separation of notification systems
- Prevents interference between specialized handlers
- Ensures notifications reach their intended systems
- Better system reliability and performance
- Clear boundaries between different Redis features

Implementation:
- Efficient switch statement with O(1) lookup
- Case-sensitive matching for precise filtering
- Comprehensive documentation for each notification type
- Applied to all processing points (WithReader, Pool.Put, isHealthyConn)

Test coverage:
- TestShouldSkipNotification with categorized test cases
- All notification types tested (pub/sub, streams, keyspace, client tracking)
- Cluster notifications verified as non-filtered
- Edge cases and boundary conditions covered
This commit is contained in:
Nedyalko Dyakov
2025-06-28 02:07:48 +03:00
parent f66518cf3a
commit f4ff2d667c
2 changed files with 44 additions and 14 deletions

View File

@ -150,8 +150,8 @@ func testProcessPendingNotifications(processor *Processor, ctx context.Context,
break
}
// Skip pub/sub messages - they should be handled by the pub/sub system
if isPubSubMessage(notificationName) {
// Skip notifications that should be handled by other systems
if shouldSkipNotification(notificationName) {
break
}
@ -659,8 +659,8 @@ func TestVoidProcessor(t *testing.T) {
})
}
// TestIsPubSubMessage tests the isPubSubMessage function
func TestIsPubSubMessage(t *testing.T) {
// TestShouldSkipNotification tests the shouldSkipNotification function
func TestShouldSkipNotification(t *testing.T) {
t.Run("PubSubMessages", func(t *testing.T) {
pubSubMessages := []string{
"message", // Regular pub/sub message
@ -673,8 +673,8 @@ func TestIsPubSubMessage(t *testing.T) {
}
for _, msgType := range pubSubMessages {
if !isPubSubMessage(msgType) {
t.Errorf("isPubSubMessage(%q) should return true", msgType)
if !shouldSkipNotification(msgType) {
t.Errorf("shouldSkipNotification(%q) should return true", msgType)
}
}
})
@ -693,8 +693,8 @@ func TestIsPubSubMessage(t *testing.T) {
}
for _, msgType := range nonPubSubMessages {
if isPubSubMessage(msgType) {
t.Errorf("isPubSubMessage(%q) should return false", msgType)
if shouldSkipNotification(msgType) {
t.Errorf("shouldSkipNotification(%q) should return false", msgType)
}
}
})