@@ -113,6 +113,7 @@ pin_project! {
113113 disconnect_notifier: Option <Box <dyn DisconnectNotifier >>,
114114 is_stream_closed: Arc <AtomicBool >,
115115 response_sync_lost: bool ,
116+ cache: Option <Arc <dyn GlideCache >>,
116117 }
117118
118119 impl <T > PinnedDrop for PipelineSink <T > {
@@ -140,6 +141,7 @@ where
140141 push_manager : Arc < ArcSwap < PushManager > > ,
141142 disconnect_notifier : Option < Box < dyn DisconnectNotifier > > ,
142143 is_stream_closed : Arc < AtomicBool > ,
144+ cache : Option < Arc < dyn GlideCache > > ,
143145 ) -> Self
144146 where
145147 T : Sink < SinkItem , Error = RedisError > + Stream < Item = RedisResult < Value > > + ' static ,
@@ -152,6 +154,7 @@ where
152154 disconnect_notifier,
153155 is_stream_closed,
154156 response_sync_lost : false ,
157+ cache,
155158 }
156159 }
157160
@@ -194,6 +197,26 @@ where
194197 if let Ok ( res) = & result {
195198 if let Value :: Push { kind, data : _data } = res {
196199 self_. push_manager . load ( ) . try_send_raw ( res) ;
200+ if kind == & PushKind :: Invalidate {
201+ if let Some ( cache) = self_. cache {
202+ match _data. first ( ) {
203+ Some ( Value :: Array ( keys) ) => {
204+ for key in keys {
205+ if let Value :: BulkString ( k) = key {
206+ cache. invalidate ( k) ;
207+ } else if let Value :: VerbatimString { text, .. } = key {
208+ cache. invalidate ( text. as_bytes ( ) ) ;
209+ }
210+ }
211+ }
212+ Some ( Value :: Nil ) => {
213+ cache. flush_all ( ) ;
214+ }
215+ None => { /* malformed push, ignore */ }
216+ _ => { }
217+ }
218+ }
219+ }
197220 if !kind. has_reply ( ) {
198221 return ;
199222 }
@@ -503,6 +526,7 @@ where
503526 fn new < T > (
504527 sink_stream : T ,
505528 disconnect_notifier : Option < Box < dyn DisconnectNotifier > > ,
529+ cache : Option < Arc < dyn GlideCache > > ,
506530 ) -> ( Self , impl Future < Output = ( ) > )
507531 where
508532 T : Sink < SinkItem , Error = RedisError > + Stream < Item = RedisResult < Value > > + ' static ,
@@ -521,6 +545,7 @@ where
521545 push_manager. clone ( ) ,
522546 disconnect_notifier,
523547 is_stream_closed. clone ( ) ,
548+ cache,
524549 ) ;
525550 let f = stream:: poll_fn ( move |cx| receiver. poll_recv ( cx) )
526551 . map ( Ok )
@@ -702,8 +727,11 @@ impl MultiplexedConnection {
702727 let codec = ValueCodec :: default ( )
703728 . framed ( stream)
704729 . and_then ( |msg| async move { msg } ) ;
705- let ( mut pipeline, driver) =
706- Pipeline :: new ( codec, glide_connection_options. disconnect_notifier ) ;
730+ let ( mut pipeline, driver) = Pipeline :: new (
731+ codec,
732+ glide_connection_options. disconnect_notifier ,
733+ connection_info. redis . cache . clone ( ) ,
734+ ) ;
707735 let driver = Box :: pin ( driver) ;
708736 let pm = PushManager :: new (
709737 glide_connection_options. push_sender ,
@@ -1160,7 +1188,7 @@ mod tests {
11601188 } ;
11611189
11621190 // Create pipeline but don't drive it, the channel will fill and send() will block
1163- let ( mut pipeline, driver) = Pipeline :: new ( stalling_sink, None ) ;
1191+ let ( mut pipeline, driver) = Pipeline :: new ( stalling_sink, None , None ) ;
11641192 std:: mem:: forget ( driver) ;
11651193
11661194 // Fill the 50-slot pipeline channel
@@ -1299,7 +1327,7 @@ mod tests {
12991327 waker : None ,
13001328 } ;
13011329
1302- let ( pipeline, driver) = Pipeline :: new ( stream, None ) ;
1330+ let ( pipeline, driver) = Pipeline :: new ( stream, None , None ) ;
13031331 let driver_handle = tokio:: spawn ( driver) ;
13041332
13051333 // Send first command — this should go through fine
0 commit comments