@@ -530,6 +530,19 @@ export default class RedisClient<
530530 this . #clientSideCache?. invalidate ( null )
531531 }
532532
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+ }
533546 return true
534547 } ) ;
535548 }
@@ -539,14 +552,15 @@ export default class RedisClient<
539552 if ( options ?. clientSideCache && options ?. RESP !== 3 ) {
540553 throw new Error ( 'Client Side Caching is only supported with RESP3' ) ;
541554 }
555+ if ( options ?. emitInvalidate && options ?. RESP !== 3 ) {
556+ throw new Error ( 'emitInvalidate is only supported with RESP3' ) ;
557+ }
542558 if ( options ?. clientSideCache && options ?. emitInvalidate ) {
543559 throw new Error ( 'emitInvalidate is not supported (or necessary) when clientSideCache is enabled' ) ;
560+ }
544561 if ( options ?. maintPushNotifications && options ?. maintPushNotifications !== 'disabled' && options ?. RESP !== 3 ) {
545562 throw new Error ( 'Graceful Maintenance is only supported with RESP3' ) ;
546- }
547-
548- }
549-
563+ }
550564 }
551565
552566 #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<
756770 commands . push ( { cmd : this . #clientSideCache. trackingOn ( ) } ) ;
757771 }
758772
773+ if ( this . #options?. emitInvalidate ) {
774+ commands . push ( { cmd : [ 'CLIENT' , 'TRACKING' , 'ON' ] } ) ;
775+ }
776+
759777 const { tls, host } = this . #options! . socket as RedisTcpSocketOptions ;
760778 const maintenanceHandshakeCmd = await EnterpriseMaintenanceManager . getHandshakeCommand ( ! ! tls , host ! , this . #options! ) ;
761779 if ( maintenanceHandshakeCmd ) {
0 commit comments