Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It enables you to set and query its data or use its PubSub topics to react to in
process their responses as soon as results come in.
The Promise-based design provides a *sane* interface to working with async responses.
* **Event-driven core** -
Register your event handler callbacks to react to incoming events, such as an incoming PubSub message or a MONITOR event.
Register your event handler callbacks to react to incoming events, such as an incoming PubSub message event.
* **Lightweight, SOLID design** -
Provides a thin abstraction that is [*just good enough*](http://en.wikipedia.org/wiki/Principle_of_good_enough)
and does not get in your way.
Expand Down Expand Up @@ -236,11 +236,6 @@ $client->on('unsubscribe', function ($channel, $total) {
$client->on('punsubscribe', function ($pattern, $total) {
// unsubscribed from matching given $pattern
});

// monitor events:
$client->on('monitor', function (StatusReply $message) {
// somebody executed a command
});
```

#### close()
Expand Down
24 changes: 0 additions & 24 deletions examples/monitor.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
* @event pmessage($pattern, $channel, $message)
* @event psubscribe($channel, $numberOfChannels)
* @event punsubscribe($channel, $numberOfChannels)
*
* @event monitor(ModelInterface $statusModel)
*/
interface Client extends EventEmitterInterface
{
Expand Down
22 changes: 3 additions & 19 deletions src/StreamingClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Clue\Redis\Protocol\Model\ErrorReply;
use Clue\Redis\Protocol\Model\ModelInterface;
use Clue\Redis\Protocol\Model\MultiBulkReply;
use Clue\Redis\Protocol\Model\StatusReply;
use React\Stream\DuplexStreamInterface;

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

private $subscribed = 0;
private $psubscribed = 0;
private $monitoring = false;

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

if ($name === 'monitor') {
$monitoring =& $this->monitoring;
$promise->then(function () use (&$monitoring) {
$monitoring = true;
});
} elseif (in_array($name, $pubsubs)) {
if (in_array($name, $pubsubs)) {
$that = $this;
$subscribed =& $this->subscribed;
$psubscribed =& $this->psubscribed;
Expand All @@ -124,11 +119,6 @@ public function __call($name, $args)

public function handleMessage(ModelInterface $message)
{
if ($this->monitoring && $this->isMonitorMessage($message)) {
$this->emit('monitor', array($message));
return;
}

if (($this->subscribed !== 0 || $this->psubscribed !== 0) && $message instanceof MultiBulkReply) {
$array = $message->getValueNative();
$first = array_shift($array);
Expand Down Expand Up @@ -192,10 +182,4 @@ public function close()
$request->reject(new RuntimeException('Connection closing'));
}
}

private function isMonitorMessage(ModelInterface $message)
{
// Check status '1409172115.207170 [0 127.0.0.1:58567] "ping"' contains otherwise uncommon '] "'
return ($message instanceof StatusReply && strpos($message->getValueNative(), '] "') !== false);
}
}
12 changes: 0 additions & 12 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,6 @@ public function testMultiExecQueuedExecHasValues()
$this->waitFor($client);
}

public function testMonitorPing()
{
$client = $this->client;

$client->on('monitor', $this->expectCallableOnce());

$client->monitor()->then($this->expectCallableOnce('OK'));
$client->ping()->then($this->expectCallableOnce('PONG'));

$this->waitFor($client);
}

public function testPubSub()
{
$consumer = $this->client;
Expand Down
45 changes: 3 additions & 42 deletions tests/StreamingClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Clue\Redis\Protocol\Model\ErrorReply;
use Clue\Redis\Protocol\Model\MultiBulkReply;
use Clue\React\Redis\Client;
use Clue\Redis\Protocol\Model\StatusReply;

class StreamingClientTest extends TestCase
{
Expand Down Expand Up @@ -81,52 +80,14 @@ public function testPingPong()
$promise->then($this->expectCallableOnce('PONG'));
}

/**
* @expectedException UnderflowException
*/
public function testInvalidMonitor()
{
$this->client->handleMessage(new StatusReply('+1409171800.312243 [0 127.0.0.1:58542] "ping"'));
}

public function testMonitor()
public function testMonitorCommandIsNotSupported()
{
$this->serializer->expects($this->once())->method('getRequestMessage')->with($this->equalTo('monitor'));

$promise = $this->client->monitor();

$this->client->handleMessage(new StatusReply('OK'));

$this->expectPromiseResolve($promise);
$promise->then($this->expectCallableOnce('OK'));
}

public function testMonitorEventFromOtherConnection()
{
// enter MONITOR mode
$client = $this->client;
$client->monitor();
$client->handleMessage(new StatusReply('OK'));

// expect a single "monitor" event when a matching status reply comes in
$client->on('monitor', $this->expectCallableOnce());
$client->handleMessage(new StatusReply('1409171800.312243 [0 127.0.0.1:58542] "ping"'));
$this->expectPromiseReject($promise);
$this->assertFalse($this->client->isBusy());
}

public function testMonitorEventFromPingMessage()
{
// enter MONITOR mode
$client = $this->client;
$client->monitor();
$client->handleMessage(new StatusReply('OK'));

// expect a single "monitor" event when a matching status reply comes in
// ignore the status reply for the command executed (ping)
$client->on('monitor', $this->expectCallableOnce());
$client->ping();
$client->handleMessage(new StatusReply('1409171800.312243 [0 127.0.0.1:58542] "ping"'));
$client->handleMessage(new StatusReply('PONG'));
}

public function testErrorReply()
{
Expand Down