Skip to content

Commit 03c6922

Browse files
committed
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
1 parent def5d19 commit 03c6922

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

push_notifications.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,8 @@ const (
225225

226226
// PushNotificationInfo contains metadata about a push notification.
227227
type PushNotificationInfo struct {
228-
Command string
229-
Args []interface{}
230-
Timestamp int64
231-
Source string
228+
Command string
229+
Args []interface{}
232230
}
233231

234232
// ParsePushNotificationInfo extracts information from a push notification.

redis.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,11 @@ func newConn(opt *Options, connPool pool.Pooler, parentHooks *hooksMixin) *Conn
982982
c.hooksMixin = parentHooks.clone()
983983
}
984984

985+
// Set push notification processor if available in options
986+
if opt.PushNotificationProcessor != nil {
987+
c.pushProcessor = opt.PushNotificationProcessor
988+
}
989+
985990
c.cmdable = c.Process
986991
c.statefulCmdable = c.Process
987992
c.initHooks(hooks{
@@ -1000,6 +1005,29 @@ func (c *Conn) Process(ctx context.Context, cmd Cmder) error {
10001005
return err
10011006
}
10021007

1008+
// RegisterPushNotificationHandler registers a handler for a specific push notification command.
1009+
// Returns an error if a handler is already registered for this command.
1010+
func (c *Conn) RegisterPushNotificationHandler(command string, handler PushNotificationHandler) error {
1011+
if c.pushProcessor != nil {
1012+
return c.pushProcessor.RegisterHandler(command, handler)
1013+
}
1014+
return nil
1015+
}
1016+
1017+
// RegisterPushNotificationHandlerFunc registers a function as a handler for a specific push notification command.
1018+
// Returns an error if a handler is already registered for this command.
1019+
func (c *Conn) RegisterPushNotificationHandlerFunc(command string, handlerFunc func(ctx context.Context, notification []interface{}) bool) error {
1020+
if c.pushProcessor != nil {
1021+
return c.pushProcessor.RegisterHandlerFunc(command, handlerFunc)
1022+
}
1023+
return nil
1024+
}
1025+
1026+
// GetPushNotificationProcessor returns the push notification processor.
1027+
func (c *Conn) GetPushNotificationProcessor() *PushNotificationProcessor {
1028+
return c.pushProcessor
1029+
}
1030+
10031031
func (c *Conn) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error) {
10041032
return c.Pipeline().Pipelined(ctx, fn)
10051033
}

0 commit comments

Comments
 (0)