@@ -530,6 +530,19 @@ export default class RedisClient<
530
530
this . #clientSideCache?. invalidate ( null )
531
531
}
532
532
533
+ return true
534
+ } ) ;
535
+ } else if ( options ?. emitInvalidate ) {
536
+ this . #queue. addPushHandler ( ( push : Array < any > ) : boolean => {
537
+ if ( push [ 0 ] . toString ( ) !== 'invalidate' ) return false ;
538
+
539
+ if ( push [ 1 ] !== null ) {
540
+ for ( const key of push [ 1 ] ) {
541
+ this . emit ( 'invalidate' , key ) ;
542
+ }
543
+ } else {
544
+ this . emit ( 'invalidate' , null ) ;
545
+ }
533
546
return true
534
547
} ) ;
535
548
}
@@ -539,14 +552,15 @@ export default class RedisClient<
539
552
if ( options ?. clientSideCache && options ?. RESP !== 3 ) {
540
553
throw new Error ( 'Client Side Caching is only supported with RESP3' ) ;
541
554
}
555
+ if ( options ?. emitInvalidate && options ?. RESP !== 3 ) {
556
+ throw new Error ( 'emitInvalidate is only supported with RESP3' ) ;
557
+ }
542
558
if ( options ?. clientSideCache && options ?. emitInvalidate ) {
543
559
throw new Error ( 'emitInvalidate is not supported (or necessary) when clientSideCache is enabled' ) ;
560
+ }
544
561
if ( options ?. maintPushNotifications && options ?. maintPushNotifications !== 'disabled' && options ?. RESP !== 3 ) {
545
562
throw new Error ( 'Graceful Maintenance is only supported with RESP3' ) ;
546
- }
547
-
548
- }
549
-
563
+ }
550
564
}
551
565
552
566
#initiateOptions( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > | undefined {
@@ -756,6 +770,10 @@ export default class RedisClient<
756
770
commands . push ( { cmd : this . #clientSideCache. trackingOn ( ) } ) ;
757
771
}
758
772
773
+ if ( this . #options?. emitInvalidate ) {
774
+ commands . push ( { cmd : [ 'CLIENT' , 'TRACKING' , 'ON' ] } ) ;
775
+ }
776
+
759
777
const { tls, host } = this . #options! . socket as RedisTcpSocketOptions ;
760
778
const maintenanceHandshakeCmd = await EnterpriseMaintenanceManager . getHandshakeCommand ( ! ! tls , host ! , this . #options! ) ;
761
779
if ( maintenanceHandshakeCmd ) {
0 commit comments