package push

Import Path
	github.com/redis/go-redis/v9/push (on go.dev)

Dependency Relation
	imports 6 packages, and imported by 2 packages

Involved Source Files errors.go handler.go handler_context.go processor.go Package push provides push notifications for Redis. This is an EXPERIMENTAL API for handling push notifications from Redis. It is not yet stable and may change in the future. Although this is in a public package, in its current form public use is not advised. Pending push notifications should be processed before executing any readReply from the connection as per RESP3 specification push notifications can be sent at any time. registry.go
Package-Level Type Names (total 10)
/* sort by: | */
HandlerError represents errors related to handler operations Err error Operation ProcessorOperation PushNotificationName string Reason string (*HandlerError) Error() string (*HandlerError) Unwrap() error *HandlerError : error *HandlerError : golang.org/x/xerrors.Wrapper func NewHandlerError(operation ProcessorOperation, pushNotificationName, reason string, err error) *HandlerError
NotificationHandler defines the interface for push notification handlers. 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 an error if the notification could not be handled. *github.com/redis/go-redis/v9/maintnotifications.NotificationHandler func NotificationProcessor.GetHandler(pushNotificationName string) NotificationHandler func (*Processor).GetHandler(pushNotificationName string) NotificationHandler func (*Registry).GetHandler(pushNotificationName string) NotificationHandler func (*VoidProcessor).GetHandler(_ string) NotificationHandler func github.com/redis/go-redis/v9.(*Client).GetPushNotificationHandler(pushNotificationName string) NotificationHandler func github.com/redis/go-redis/v9.(*SentinelClient).GetPushNotificationHandler(pushNotificationName string) NotificationHandler func NotificationProcessor.RegisterHandler(pushNotificationName string, handler NotificationHandler, protected bool) error func (*Processor).RegisterHandler(pushNotificationName string, handler NotificationHandler, protected bool) error func (*Registry).RegisterHandler(pushNotificationName string, handler NotificationHandler, protected bool) error func (*VoidProcessor).RegisterHandler(pushNotificationName string, _ NotificationHandler, _ bool) error func github.com/redis/go-redis/v9.(*Client).RegisterPushNotificationHandler(pushNotificationName string, handler NotificationHandler, protected bool) error func github.com/redis/go-redis/v9.(*Conn).RegisterPushNotificationHandler(pushNotificationName string, handler NotificationHandler, protected bool) error func github.com/redis/go-redis/v9.(*SentinelClient).RegisterPushNotificationHandler(pushNotificationName string, handler NotificationHandler, protected bool) error
NotificationHandlerContext provides context information about where a push notification was received. This struct allows handlers to make informed decisions based on the source of the notification with strongly typed access to different client types using concrete types. Client is the Redis client instance that received the notification. It is interface to both allow for future expansion and to avoid circular dependencies. The developer is responsible for type assertion. It can be one of the following types: - *redis.baseClient - *redis.Client - *redis.ClusterClient - *redis.Conn Conn is the specific connection on which the notification was received. It is interface to both allow for future expansion and to avoid circular dependencies. The developer is responsible for type assertion. It can be one of the following types: - *pool.Conn ConnPool is the connection pool from which the connection was obtained. It is interface to both allow for future expansion and to avoid circular dependencies. The developer is responsible for type assertion. It can be one of the following types: - *pool.ConnPool - *pool.SingleConnPool - *pool.StickyConnPool IsBlocking indicates if the notification was received on a blocking connection. PubSub is the PubSub instance that received the notification. It is interface to both allow for future expansion and to avoid circular dependencies. The developer is responsible for type assertion. It can be one of the following types: - *redis.PubSub func NotificationHandler.HandlePushNotification(ctx context.Context, handlerCtx NotificationHandlerContext, notification []interface{}) error func NotificationProcessor.ProcessPendingNotifications(ctx context.Context, handlerCtx NotificationHandlerContext, rd *proto.Reader) error func (*Processor).ProcessPendingNotifications(ctx context.Context, handlerCtx NotificationHandlerContext, rd *proto.Reader) error func (*Processor).ProcessPendingNotificationsBuffered(ctx context.Context, handlerCtx NotificationHandlerContext, rd *proto.Reader) error func (*VoidProcessor).ProcessPendingNotifications(_ context.Context, handlerCtx NotificationHandlerContext, rd *proto.Reader) error func github.com/redis/go-redis/v9/maintnotifications.(*LoggingHook).PostHook(ctx context.Context, notificationCtx NotificationHandlerContext, notificationType string, notification []interface{}, result error) func github.com/redis/go-redis/v9/maintnotifications.(*LoggingHook).PreHook(ctx context.Context, notificationCtx NotificationHandlerContext, notificationType string, notification []interface{}) ([]interface{}, bool) func github.com/redis/go-redis/v9/maintnotifications.(*MetricsHook).PostHook(ctx context.Context, notificationCtx NotificationHandlerContext, notificationType string, notification []interface{}, result error) func github.com/redis/go-redis/v9/maintnotifications.(*MetricsHook).PreHook(ctx context.Context, notificationCtx NotificationHandlerContext, notificationType string, notification []interface{}) ([]interface{}, bool) func github.com/redis/go-redis/v9/maintnotifications.(*NotificationHandler).HandlePushNotification(ctx context.Context, handlerCtx NotificationHandlerContext, notification []interface{}) error func github.com/redis/go-redis/v9/maintnotifications.NotificationHook.PostHook(ctx context.Context, notificationCtx NotificationHandlerContext, notificationType string, notification []interface{}, result error) func github.com/redis/go-redis/v9/maintnotifications.NotificationHook.PreHook(ctx context.Context, notificationCtx NotificationHandlerContext, notificationType string, notification []interface{}) ([]interface{}, bool)
NotificationProcessor defines the interface for push notification processors. GetHandler returns the handler for a specific push notification name. ProcessPendingNotifications checks for and processes any pending push notifications. To be used when it is known that there are notifications on the socket. It will try to read from the socket and if it is empty - it may block. RegisterHandler registers a handler for a specific push notification name. UnregisterHandler removes a handler for a specific push notification name. *Processor *VoidProcessor func github.com/redis/go-redis/v9.NewPushNotificationProcessor() NotificationProcessor func github.com/redis/go-redis/v9.NewVoidPushNotificationProcessor() NotificationProcessor
Processor handles push notifications with a registry of handlers GetHandler returns the handler for a specific push notification name ProcessPendingNotifications checks for and processes any pending push notifications This method should be called by the client in WithReader before reading the reply It will try to read from the socket and if it is empty - it may block. ProcessPendingNotificationsBuffered processes one pending push notification and then continues only through frames already buffered by that read. It is used by callers that have already established socket readiness and must not wait for another frame after draining the current batch. RegisterHandler registers a handler for a specific push notification name UnregisterHandler removes a handler for a specific push notification name *Processor : NotificationProcessor func NewProcessor() *Processor
ProcessorError represents errors related to processor operations Err error // "process", "register", "unregister" // "processor", "void_processor" // Name of the push notification involved Reason string (*ProcessorError) Error() string (*ProcessorError) Unwrap() error *ProcessorError : error *ProcessorError : golang.org/x/xerrors.Wrapper func NewProcessorError(processorType ProcessorType, operation ProcessorOperation, pushNotificationName, reason string, err error) *ProcessorError
ProcessorOperation represents the operation being performed by the processor defined as a custom type for better readability and easier maintenance func NewHandlerError(operation ProcessorOperation, pushNotificationName, reason string, err error) *HandlerError func NewProcessorError(processorType ProcessorType, operation ProcessorOperation, pushNotificationName, reason string, err error) *ProcessorError const ProcessorOperationProcess const ProcessorOperationRegister const ProcessorOperationUnknown const ProcessorOperationUnregister
ProcessorType represents the type of processor involved in the error defined as a custom type for better readability and easier maintenance func NewProcessorError(processorType ProcessorType, operation ProcessorOperation, pushNotificationName, reason string, err error) *ProcessorError const ProcessorTypeCustom const ProcessorTypeProcessor const ProcessorTypeVoidProcessor
Registry manages push notification handlers GetHandler returns the handler for a specific push notification name RegisterHandler registers a handler for a specific push notification name UnregisterHandler removes a handler for a specific push notification name func NewRegistry() *Registry
VoidProcessor discards all push notifications without processing them GetHandler returns nil for void processor since it doesn't maintain handlers ProcessPendingNotifications for VoidProcessor does nothing since push notifications are only available in RESP3 and this processor is used for RESP2 connections. This avoids unnecessary buffer scanning overhead. It does however read and discard all push notifications from the buffer to avoid them being interpreted as a reply. This method should be called by the client in WithReader before reading the reply to be sure there are no buffered push notifications. It will try to read from the socket and if it is empty - it may block. RegisterHandler returns an error for void processor since it doesn't maintain handlers UnregisterHandler returns an error for void processor since it doesn't maintain handlers *VoidProcessor : NotificationProcessor func NewVoidProcessor() *VoidProcessor
Package-Level Functions (total 13)
ErrHandlerExists creates an error for when attempting to overwrite an existing handler
ErrProtectedHandler creates an error for when attempting to unregister a protected handler
ErrVoidProcessorRegister creates an error for when attempting to register a handler on void processor
ErrVoidProcessorUnregister creates an error for when attempting to unregister a handler on void processor
IsHandlerExistsError checks if an error is due to attempting to overwrite an existing handler. This function works correctly even when the error is wrapped.
IsHandlerNilError checks if an error is due to a nil handler
IsProtectedHandlerError checks if an error is due to attempting to unregister a protected handler. This function works correctly even when the error is wrapped.
IsVoidProcessorError checks if an error is due to void processor operations. This function works correctly even when the error is wrapped.
NewHandlerError creates a new HandlerError
NewProcessor creates a new push notification processor
NewProcessorError creates a new ProcessorError
NewRegistry creates a new push notification registry
NewVoidProcessor creates a new void push notification processor
Package-Level Variables (only one)
ErrHandlerNil is returned when attempting to register a nil handler
Package-Level Constants (total 11)
ProcessorOperations
ProcessorTypes
const ProcessorTypeVoidProcessor ProcessorType = "void_processor"
Error reason constants
HandlerReasons
Error reason constants
ProcessorReasons