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

feat: enhance push notification handlers with context information

This commit is contained in:
Nedyalko Dyakov
2025-07-04 17:08:08 +03:00
parent c44c8b5b03
commit 47dd490a8a
11 changed files with 242 additions and 128 deletions

View File

@ -6,17 +6,32 @@ import (
"github.com/redis/go-redis/v9/internal/proto"
)
// HandlerContext provides context information about where a push notification was received.
// This allows handlers to make informed decisions based on the source of the notification.
type HandlerContext struct {
// Client is the Redis client instance that received the notification
Client interface{}
// ConnPool is the connection pool from which the connection was obtained
ConnPool interface{}
// Conn is the specific connection on which the notification was received
Conn interface{}
}
// Handler defines the interface for push notification handlers.
type Handler interface {
// HandlePushNotification processes a push notification.
// HandlePushNotification processes a push notification with context information.
// The handlerCtx provides information about the client, connection pool, and connection
// on which the notification was received, allowing handlers to make informed decisions.
// Returns true if the notification was handled, false otherwise.
HandlePushNotification(ctx context.Context, notification []interface{}) bool
HandlePushNotification(ctx context.Context, handlerCtx *HandlerContext, notification []interface{}) bool
}
// ProcessorInterface defines the interface for push notification processors.
type ProcessorInterface interface {
GetHandler(pushNotificationName string) Handler
ProcessPendingNotifications(ctx context.Context, rd *proto.Reader) error
ProcessPendingNotifications(ctx context.Context, handlerCtx *HandlerContext, rd *proto.Reader) error
RegisterHandler(pushNotificationName string, handler Handler, protected bool) error
}