Skip to content

Commit b634de1

Browse files
committed
Remove support for MONITOR command for performance and consistency
1 parent 2dfe566 commit b634de1

File tree

6 files changed

+7
-105
lines changed

6 files changed

+7
-105
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ It enables you to set and query its data or use its PubSub topics to react to in
1313
process their responses as soon as results come in.
1414
The Promise-based design provides a *sane* interface to working with async responses.
1515
* **Event-driven core** -
16-
Register your event handler callbacks to react to incoming events, such as an incoming PubSub message or a MONITOR event.
16+
Register your event handler callbacks to react to incoming events, such as an incoming PubSub message event.
1717
* **Lightweight, SOLID design** -
1818
Provides a thin abstraction that is [*just good enough*](http://en.wikipedia.org/wiki/Principle_of_good_enough)
1919
and does not get in your way.
@@ -236,11 +236,6 @@ $client->on('unsubscribe', function ($channel, $total) {
236236
$client->on('punsubscribe', function ($pattern, $total) {
237237
// unsubscribed from matching given $pattern
238238
});
239-
240-
// monitor events:
241-
$client->on('monitor', function (StatusReply $message) {
242-
// somebody executed a command
243-
});
244239
```
245240

246241
#### close()

examples/monitor.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/Client.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
* @event pmessage($pattern, $channel, $message)
1919
* @event psubscribe($channel, $numberOfChannels)
2020
* @event punsubscribe($channel, $numberOfChannels)
21-
*
22-
* @event monitor(ModelInterface $statusModel)
2321
*/
2422
interface Client extends EventEmitterInterface
2523
{

src/StreamingClient.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Clue\Redis\Protocol\Model\ErrorReply;
1515
use Clue\Redis\Protocol\Model\ModelInterface;
1616
use Clue\Redis\Protocol\Model\MultiBulkReply;
17-
use Clue\Redis\Protocol\Model\StatusReply;
1817
use React\Stream\DuplexStreamInterface;
1918

2019
/**
@@ -31,7 +30,6 @@ class StreamingClient extends EventEmitter implements Client
3130

3231
private $subscribed = 0;
3332
private $psubscribed = 0;
34-
private $monitoring = false;
3533

3634
public function __construct(DuplexStreamInterface $stream, ParserInterface $parser = null, SerializerInterface $serializer = null)
3735
{
@@ -89,17 +87,14 @@ public function __call($name, $args)
8987
$request->reject(new RuntimeException('Connection closed'));
9088
} elseif (count($args) !== 1 && in_array($name, $pubsubs)) {
9189
$request->reject(new InvalidArgumentException('PubSub commands limited to single argument'));
90+
} elseif ($name === 'monitor') {
91+
$request->reject(new \BadMethodCallException('MONITOR command explicitly not supported'));
9292
} else {
9393
$this->stream->write($this->serializer->getRequestMessage($name, $args));
9494
$this->requests []= $request;
9595
}
9696

97-
if ($name === 'monitor') {
98-
$monitoring =& $this->monitoring;
99-
$promise->then(function () use (&$monitoring) {
100-
$monitoring = true;
101-
});
102-
} elseif (in_array($name, $pubsubs)) {
97+
if (in_array($name, $pubsubs)) {
10398
$that = $this;
10499
$subscribed =& $this->subscribed;
105100
$psubscribed =& $this->psubscribed;
@@ -124,11 +119,6 @@ public function __call($name, $args)
124119

125120
public function handleMessage(ModelInterface $message)
126121
{
127-
if ($this->monitoring && $this->isMonitorMessage($message)) {
128-
$this->emit('monitor', array($message));
129-
return;
130-
}
131-
132122
if (($this->subscribed !== 0 || $this->psubscribed !== 0) && $message instanceof MultiBulkReply) {
133123
$array = $message->getValueNative();
134124
$first = array_shift($array);
@@ -192,10 +182,4 @@ public function close()
192182
$request->reject(new RuntimeException('Connection closing'));
193183
}
194184
}
195-
196-
private function isMonitorMessage(ModelInterface $message)
197-
{
198-
// Check status '1409172115.207170 [0 127.0.0.1:58567] "ping"' contains otherwise uncommon '] "'
199-
return ($message instanceof StatusReply && strpos($message->getValueNative(), '] "') !== false);
200-
}
201185
}

tests/FunctionalTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,6 @@ public function testMultiExecQueuedExecHasValues()
9494
$this->waitFor($client);
9595
}
9696

97-
public function testMonitorPing()
98-
{
99-
$client = $this->client;
100-
101-
$client->on('monitor', $this->expectCallableOnce());
102-
103-
$client->monitor()->then($this->expectCallableOnce('OK'));
104-
$client->ping()->then($this->expectCallableOnce('PONG'));
105-
106-
$this->waitFor($client);
107-
}
108-
10997
public function testPubSub()
11098
{
11199
$consumer = $this->client;

tests/StreamingClientTest.php

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Clue\Redis\Protocol\Model\ErrorReply;
88
use Clue\Redis\Protocol\Model\MultiBulkReply;
99
use Clue\React\Redis\Client;
10-
use Clue\Redis\Protocol\Model\StatusReply;
1110

1211
class StreamingClientTest extends TestCase
1312
{
@@ -81,52 +80,14 @@ public function testPingPong()
8180
$promise->then($this->expectCallableOnce('PONG'));
8281
}
8382

84-
/**
85-
* @expectedException UnderflowException
86-
*/
87-
public function testInvalidMonitor()
88-
{
89-
$this->client->handleMessage(new StatusReply('+1409171800.312243 [0 127.0.0.1:58542] "ping"'));
90-
}
91-
92-
public function testMonitor()
83+
public function testMonitorCommandIsNotSupported()
9384
{
94-
$this->serializer->expects($this->once())->method('getRequestMessage')->with($this->equalTo('monitor'));
95-
9685
$promise = $this->client->monitor();
9786

98-
$this->client->handleMessage(new StatusReply('OK'));
99-
100-
$this->expectPromiseResolve($promise);
101-
$promise->then($this->expectCallableOnce('OK'));
102-
}
103-
104-
public function testMonitorEventFromOtherConnection()
105-
{
106-
// enter MONITOR mode
107-
$client = $this->client;
108-
$client->monitor();
109-
$client->handleMessage(new StatusReply('OK'));
110-
111-
// expect a single "monitor" event when a matching status reply comes in
112-
$client->on('monitor', $this->expectCallableOnce());
113-
$client->handleMessage(new StatusReply('1409171800.312243 [0 127.0.0.1:58542] "ping"'));
87+
$this->expectPromiseReject($promise);
88+
$this->assertFalse($this->client->isBusy());
11489
}
11590

116-
public function testMonitorEventFromPingMessage()
117-
{
118-
// enter MONITOR mode
119-
$client = $this->client;
120-
$client->monitor();
121-
$client->handleMessage(new StatusReply('OK'));
122-
123-
// expect a single "monitor" event when a matching status reply comes in
124-
// ignore the status reply for the command executed (ping)
125-
$client->on('monitor', $this->expectCallableOnce());
126-
$client->ping();
127-
$client->handleMessage(new StatusReply('1409171800.312243 [0 127.0.0.1:58542] "ping"'));
128-
$client->handleMessage(new StatusReply('PONG'));
129-
}
13091

13192
public function testErrorReply()
13293
{

0 commit comments

Comments
 (0)