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
36 changes: 18 additions & 18 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
use Clue\Redis\Protocol\Model\ErrorReplyException;
use Clue\Redis\Protocol\Serializer\SerializerInterface;
use Clue\Redis\Protocol\Factory as ProtocolFactory;
use Clue\React\Redis\Request;
use UnderflowException;
use RuntimeException;
use React\Promise\Deferred;
use Clue\Redis\Protocol\Model\ErrorReply;
use Clue\Redis\Protocol\Model\ModelInterface;

class Client extends EventEmitter
{
Expand Down Expand Up @@ -46,7 +48,7 @@ public function __construct(Stream $stream, ParserInterface $parser = null, Seri

foreach ($models as $data) {
try {
$that->handleReply($data);
$that->handleMessage($data);
}
catch (UnderflowException $error) {
$that->emit('error', array($error));
Expand All @@ -67,36 +69,34 @@ public function __construct(Stream $stream, ParserInterface $parser = null, Seri

public function __call($name, $args)
{
if ($this->ending) {
$e = new RuntimeException('Connection closed');
$request = new Deferred();

if (class_exists('React\Promise\When')) {
return \React\Promise\When::reject($e);
} else {
return \React\Promise\reject($e);
}
if ($this->ending) {
$request->reject(new RuntimeException('Connection closed'));
} else {
$this->stream->write($this->serializer->getRequestMessage($name, $args));
$this->requests []= $request;
}

$this->stream->write($this->serializer->getRequestMessage($name, $args));

$request = new Request($name);
$this->requests []= $request;

return $request->promise();
}

public function handleReply($data)
public function handleMessage(ModelInterface $message)
{
$this->emit('message', array($data, $this));
$this->emit('message', array($message, $this));

if (!$this->requests) {
throw new UnderflowException('Unexpected reply received, no matching request found');
}

$request = array_shift($this->requests);
/* @var $request Request */
/* @var $request Deferred */

$request->handleReply($data);
if ($message instanceof ErrorReply) {
$request->reject($message);
} else {
$request->resolve($message->getValueNative());
}

if ($this->ending && !$this->isBusy()) {
$this->close();
Expand Down
19 changes: 0 additions & 19 deletions src/Request.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ClientTest.php → tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use Clue\React\Redis\Client;

class ClientTest extends TestCase
class FunctionalTest extends TestCase
{
protected static $loop;
protected static $factory;
Expand Down