2424 ErrPoolTimeout = errors .New ("redis: connection pool timeout" )
2525)
2626
27+
28+
2729var timers = sync.Pool {
2830 New : func () interface {} {
2931 t := time .NewTimer (time .Hour )
@@ -60,6 +62,12 @@ type Pooler interface {
6062 Close () error
6163}
6264
65+ // PushNotificationProcessorInterface defines the interface for push notification processors.
66+ // This matches the main PushNotificationProcessorInterface to avoid duplication while preventing circular imports.
67+ type PushNotificationProcessorInterface interface {
68+ ProcessPendingNotifications (ctx context.Context , rd * proto.Reader ) error
69+ }
70+
6371type Options struct {
6472 Dialer func (context.Context ) (net.Conn , error )
6573
@@ -74,9 +82,12 @@ type Options struct {
7482 ConnMaxLifetime time.Duration
7583
7684 // Push notification processor for connections
77- PushNotificationProcessor interface {
78- ProcessPendingNotifications (ctx context.Context , rd * proto.Reader ) error
79- }
85+ // This interface matches PushNotificationProcessorInterface to avoid duplication
86+ // while preventing circular imports
87+ PushNotificationProcessor PushNotificationProcessorInterface
88+
89+ // Protocol version for optimization (3 = RESP3 with push notifications, 2 = RESP2 without)
90+ Protocol int
8091}
8192
8293type lastDialErrorWrap struct {
@@ -390,8 +401,8 @@ func (p *ConnPool) popIdle() (*Conn, error) {
390401func (p * ConnPool ) Put (ctx context.Context , cn * Conn ) {
391402 if cn .rd .Buffered () > 0 {
392403 // Check if this might be push notification data
393- if cn .PushNotificationProcessor != nil {
394- // Try to process pending push notifications before discarding connection
404+ if cn .PushNotificationProcessor != nil && p . cfg . Protocol == 3 {
405+ // Only process for RESP3 clients ( push notifications only available in RESP3)
395406 err := cn .PushNotificationProcessor .ProcessPendingNotifications (ctx , cn .rd )
396407 if err != nil {
397408 internal .Logger .Printf (ctx , "push: error processing pending notifications: %v" , err )
@@ -553,9 +564,9 @@ func (p *ConnPool) isHealthyConn(cn *Conn) bool {
553564 // Check connection health, but be aware of push notifications
554565 if err := connCheck (cn .netConn ); err != nil {
555566 // If there's unexpected data and we have push notification support,
556- // it might be push notifications
557- if err == errUnexpectedRead && cn .PushNotificationProcessor != nil {
558- // Try to process any pending push notifications
567+ // it might be push notifications (only for RESP3)
568+ if err == errUnexpectedRead && cn .PushNotificationProcessor != nil && p . cfg . Protocol == 3 {
569+ // Try to process any pending push notifications (only for RESP3)
559570 ctx := context .Background ()
560571 if procErr := cn .PushNotificationProcessor .ProcessPendingNotifications (ctx , cn .rd ); procErr != nil {
561572 internal .Logger .Printf (ctx , "push: error processing pending notifications during health check: %v" , procErr )
0 commit comments