1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

refactor(push): simplify handler context

This commit is contained in:
Nedyalko Dyakov
2025-07-05 03:11:11 +03:00
parent 84123b1331
commit d78040165a
5 changed files with 200 additions and 353 deletions

View File

@ -5,85 +5,38 @@ import (
)
// NotificationHandlerContext provides context information about where a push notification was received.
// This interface allows handlers to make informed decisions based on the source of the notification
// 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.
type NotificationHandlerContext interface {
// GetClient returns the Redis client instance that received the notification.
// Returns nil if no client context is available.
type NotificationHandlerContext struct {
// 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
GetClient() interface{}
Client interface{}
// GetConnPool returns the connection pool from which the connection was obtained.
// Returns nil if no connection pool context is available.
// 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
GetConnPool() interface{}
ConnPool interface{}
// GetPubSub returns the PubSub instance that received the notification.
// Returns nil if this is not a PubSub 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
GetPubSub() interface{}
PubSub interface{}
// GetConn returns the specific connection on which the notification was received.
// Returns nil if no connection context is available.
GetConn() *pool.Conn
// Conn is the specific connection on which the notification was received.
Conn *pool.Conn
// IsBlocking returns true if the notification was received on a blocking connection.
IsBlocking() bool
}
// pushNotificationHandlerContext is the concrete implementation of PushNotificationHandlerContext interface
type pushNotificationHandlerContext struct {
client interface{}
connPool interface{}
pubSub interface{}
conn *pool.Conn
isBlocking bool
}
// NewNotificationHandlerContext creates a new push.NotificationHandlerContext instance
func NewNotificationHandlerContext(client, connPool, pubSub interface{}, conn *pool.Conn, isBlocking bool) NotificationHandlerContext {
return &pushNotificationHandlerContext{
client: client,
connPool: connPool,
pubSub: pubSub,
conn: conn,
isBlocking: isBlocking,
}
}
// GetClient returns the Redis client instance that received the notification
func (h *pushNotificationHandlerContext) GetClient() interface{} {
return h.client
}
// GetConnPool returns the connection pool from which the connection was obtained
func (h *pushNotificationHandlerContext) GetConnPool() interface{} {
return h.connPool
}
func (h *pushNotificationHandlerContext) GetPubSub() interface{} {
return h.pubSub
}
// GetConn returns the specific connection on which the notification was received
func (h *pushNotificationHandlerContext) GetConn() *pool.Conn {
return h.conn
}
// IsBlocking returns true if the notification was received on a blocking connection
func (h *pushNotificationHandlerContext) IsBlocking() bool {
return h.isBlocking
// IsBlocking indicates if the notification was received on a blocking connection.
IsBlocking bool
}