mirror of
https://github.com/redis/go-redis.git
synced 2025-07-18 00:20:57 +03:00
fix: remove unused fields and ensure push notifications work in cloned clients
- Remove unused Timestamp and Source fields from PushNotificationInfo - Add pushProcessor to newConn function to ensure Conn instances have push notifications - Add push notification methods to Conn type for consistency - Ensure cloned clients and Conn instances preserve push notification functionality This fixes issues where: 1. PushNotificationInfo had unused fields causing confusion 2. Conn instances created via client.Conn() lacked push notification support 3. All client types now consistently support push notifications
This commit is contained in:
@ -227,8 +227,6 @@ const (
|
||||
type PushNotificationInfo struct {
|
||||
Command string
|
||||
Args []interface{}
|
||||
Timestamp int64
|
||||
Source string
|
||||
}
|
||||
|
||||
// ParsePushNotificationInfo extracts information from a push notification.
|
||||
|
28
redis.go
28
redis.go
@ -982,6 +982,11 @@ func newConn(opt *Options, connPool pool.Pooler, parentHooks *hooksMixin) *Conn
|
||||
c.hooksMixin = parentHooks.clone()
|
||||
}
|
||||
|
||||
// Set push notification processor if available in options
|
||||
if opt.PushNotificationProcessor != nil {
|
||||
c.pushProcessor = opt.PushNotificationProcessor
|
||||
}
|
||||
|
||||
c.cmdable = c.Process
|
||||
c.statefulCmdable = c.Process
|
||||
c.initHooks(hooks{
|
||||
@ -1000,6 +1005,29 @@ func (c *Conn) Process(ctx context.Context, cmd Cmder) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// RegisterPushNotificationHandler registers a handler for a specific push notification command.
|
||||
// Returns an error if a handler is already registered for this command.
|
||||
func (c *Conn) RegisterPushNotificationHandler(command string, handler PushNotificationHandler) error {
|
||||
if c.pushProcessor != nil {
|
||||
return c.pushProcessor.RegisterHandler(command, handler)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterPushNotificationHandlerFunc registers a function as a handler for a specific push notification command.
|
||||
// Returns an error if a handler is already registered for this command.
|
||||
func (c *Conn) RegisterPushNotificationHandlerFunc(command string, handlerFunc func(ctx context.Context, notification []interface{}) bool) error {
|
||||
if c.pushProcessor != nil {
|
||||
return c.pushProcessor.RegisterHandlerFunc(command, handlerFunc)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPushNotificationProcessor returns the push notification processor.
|
||||
func (c *Conn) GetPushNotificationProcessor() *PushNotificationProcessor {
|
||||
return c.pushProcessor
|
||||
}
|
||||
|
||||
func (c *Conn) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error) {
|
||||
return c.Pipeline().Pipelined(ctx, fn)
|
||||
}
|
||||
|
Reference in New Issue
Block a user