1515use Clue \Redis \Protocol \Model \ErrorReply ;
1616use Clue \Redis \Protocol \Model \ModelInterface ;
1717use Clue \Redis \Protocol \Model \MultiBulkReply ;
18+ use Clue \Redis \Protocol \Model \StatusReply ;
1819
1920class StreamingClient extends EventEmitter implements Client
2021{
@@ -27,6 +28,7 @@ class StreamingClient extends EventEmitter implements Client
2728
2829 private $ subscribed = 0 ;
2930 private $ psubscribed = 0 ;
31+ private $ monitoring = false ;
3032
3133 public function __construct (Stream $ stream , ParserInterface $ parser = null , SerializerInterface $ serializer = null )
3234 {
@@ -82,13 +84,25 @@ public function __call($name, $args)
8284 $ this ->requests []= $ request ;
8385 }
8486
87+ if (strtolower ($ name ) === 'monitor ' ) {
88+ $ monitoring =& $ this ->monitoring ;
89+ $ request ->then (function () use (&$ monitoring ) {
90+ $ monitoring = true ;
91+ });
92+ }
93+
8594 return $ request ->promise ();
8695 }
8796
8897 public function handleMessage (ModelInterface $ message )
8998 {
9099 $ this ->emit ('data ' , array ($ message , $ this ));
91100
101+ if ($ this ->monitoring && $ this ->isMonitorMessage ($ message )) {
102+ $ this ->emit ('monitor ' , array ($ message ));
103+ return ;
104+ }
105+
92106 if (/*($this->subscribed !== 0 || $this->psubscribed !== 0) &&*/ $ message instanceof MultiBulkReply) {
93107 $ array = $ message ->getValueNative ();
94108 $ first = array_shift ($ array );
@@ -156,4 +170,10 @@ public function close()
156170 $ request ->reject (new RuntimeException ('Connection closing ' ));
157171 }
158172 }
173+
174+ private function isMonitorMessage (ModelInterface $ message )
175+ {
176+ // Check status '1409172115.207170 [0 127.0.0.1:58567] "ping"' contains otherwise uncommon '] "'
177+ return ($ message instanceof StatusReply && strpos ($ message ->getValueNative (), '] " ' ) !== false );
178+ }
159179}
0 commit comments