Skip to content

Commit

Permalink
fix bug: writable event continus fired after the first command sent t…
Browse files Browse the repository at this point in the history
…o redis server.
  • Loading branch information
bixuehujin committed Aug 24, 2013
1 parent 7992c0f commit 63aaeaa
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/Predis/Async/Connection/StreamConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class StreamConnection implements ConnectionInterface
protected $errorCallback = null;
protected $readableCallback = null;
protected $writableCallback = null;

protected $writeStreamOn = false;

/**
* @param ConnectionParametersInterface $parameters
* @param LoopInterface $loop
Expand Down Expand Up @@ -375,6 +376,10 @@ protected function getIdentifier()
public function write()
{
if ($this->buffer->isEmpty()) {
if ($this->commands->isEmpty()) {
$this->loop->removeWriteStream($this->getResource());
$this->writeStreamOn = false;
}
return false;
}

Expand Down Expand Up @@ -414,13 +419,13 @@ public function executeCommand(CommandInterface $command, $callback)
{
$cmdargs = $command->getArguments();
array_unshift($cmdargs, $command->getId());

if ($this->buffer->isEmpty()) {
$this->loop->addWriteStream($this->getResource(), $this->writableCallback);
}


$this->buffer->append(phpiredis_format_command($cmdargs));
$this->commands->enqueue(array($command, $callback));

if (!$this->writeStreamOn) {
$this->loop->addWriteStream($this->getResource(), $this->writableCallback);
}
}

/**
Expand Down

0 comments on commit 63aaeaa

Please sign in to comment.