Rename write and read methods of the composable connection interface.

This commit is contained in:
Daniele Alessandri
2013-12-10 21:26:11 +01:00
parent 59b5658cf5
commit 95b9f63cab
15 changed files with 35 additions and 34 deletions
@@ -27,18 +27,19 @@ interface ComposableConnectionInterface extends SingleConnectionInterface
public function getProtocol();
/**
* Writes the buffer containing a serialized command over the connection.
* Writes the buffer containing over the connection.
*
* @param string $buffer Serialized Redis command.
* @param string $buffer String buffer to be sent over the connection.
*/
public function writeBytes($buffer);
public function writeBuffer($buffer);
/**
* Reads the given number of bytes from the connection.
*
* @param string
* @param int $length Number of bytes to read from the connection.
* @return string
*/
public function readBytes($length);
public function readBuffer($length);
/**
* Reads a line from the connection.
@@ -48,15 +48,15 @@ class ComposableStreamConnection extends StreamConnection implements ComposableC
/**
* {@inheritdoc}
*/
public function writeBytes($buffer)
public function writeBuffer($buffer)
{
parent::writeBytes($buffer);
$this->write($buffer);
}
/**
* {@inheritdoc}
*/
public function readBytes($length)
public function readBuffer($length)
{
if ($length <= 0) {
throw new \InvalidArgumentException('Length parameter must be greater than 0');
@@ -165,7 +165,7 @@ class PhpiredisStreamConnection extends StreamConnection
$arguments = $command->getArguments();
array_unshift($arguments, $command->getId());
$this->writeBytes(phpiredis_format_command($arguments));
$this->write(phpiredis_format_command($arguments));
}
/**
+2 -2
View File
@@ -151,7 +151,7 @@ class StreamConnection extends AbstractConnection
*
* @param string $buffer Representation of a command in the Redis wire protocol.
*/
protected function writeBytes($buffer)
protected function write($buffer)
{
$socket = $this->getResource();
@@ -257,6 +257,6 @@ class StreamConnection extends AbstractConnection
$buffer .= "\${$arglen}\r\n{$argument}\r\n";
}
$this->writeBytes($buffer);
$this->write($buffer);
}
}
@@ -46,7 +46,7 @@ class ComposableProtocolProcessor implements ProtocolProcessorInterface
*/
public function write(ComposableConnectionInterface $connection, CommandInterface $command)
{
$connection->writeBytes($this->serializer->serialize($command));
$connection->writeBuffer($this->serializer->serialize($command));
}
/**
@@ -38,7 +38,7 @@ class BulkResponse implements ResponseHandlerInterface
}
if ($length >= 0) {
return substr($connection->readBytes($length + 2), 0, -2);
return substr($connection->readBuffer($length + 2), 0, -2);
}
if ($length == -1) {
@@ -45,7 +45,7 @@ class ProtocolProcessor implements ProtocolProcessorInterface
public function write(ComposableConnectionInterface $connection, CommandInterface $command)
{
$request = $this->serializer->serialize($command);
$connection->writeBytes($request);
$connection->writeBuffer($request);
}
/**
@@ -66,7 +66,7 @@ class ProtocolProcessor implements ProtocolProcessorInterface
if ($size === -1) {
return null;
}
return substr($connection->readBytes($size + 2), 0, -2);
return substr($connection->readBuffer($size + 2), 0, -2);
case '*': // multi bulk
$count = (int) $payload;
@@ -87,7 +87,7 @@ class ComposableProtocolProcessorTest extends PredisTestCase
$protocol = new ComposableProtocolProcessor($serializer);
$connection->expects($this->once())
->method('writeBytes')
->method('writeBuffer')
->with($this->equalTo($serialized));
$serializer->expects($this->once())
@@ -29,7 +29,7 @@ class BulkResponseTest extends PredisTestCase
$connection->expects($this->never())->method('readLine');
$connection->expects($this->once())
->method('readBytes')
->method('readBuffer')
->with($this->equalTo(2))
->will($this->returnValue("\r\n"));
@@ -50,7 +50,7 @@ class BulkResponseTest extends PredisTestCase
$connection->expects($this->never())->method('readLine');
$connection->expects($this->once())
->method('readBytes')
->method('readBuffer')
->with($this->equalTo($bulkLengh + 2))
->will($this->returnValue("$bulk\r\n"));
@@ -67,7 +67,7 @@ class BulkResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$this->assertNull($handler->handle($connection, '-1'));
}
@@ -84,7 +84,7 @@ class BulkResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$handler->handle($connection, 'invalid');
}
@@ -28,7 +28,7 @@ class ErrorResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$message = "ERR Operation against a key holding the wrong kind of value";
$response = $handler->handle($connection, $message);
@@ -28,7 +28,7 @@ class IntegerResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$this->assertSame(0, $handler->handle($connection, '0'));
$this->assertSame(1, $handler->handle($connection, '1'));
@@ -46,7 +46,7 @@ class IntegerResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$this->assertNull($handler->handle($connection, 'nil'));
}
@@ -63,7 +63,7 @@ class IntegerResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$handler->handle($connection, 'invalid');
}
@@ -36,7 +36,7 @@ class MultiBulkResponseTest extends PredisTestCase
->will($this->returnValue("$3"));
$connection->expects($this->at(2))
->method('readBytes')
->method('readBuffer')
->will($this->returnValue("foo\r\n"));
$connection->expects($this->at(3))
@@ -44,7 +44,7 @@ class MultiBulkResponseTest extends PredisTestCase
->will($this->returnValue("$3"));
$connection->expects($this->at(4))
->method('readBytes')
->method('readBuffer')
->will($this->returnValue("bar\r\n"));
$this->assertSame(array('foo', 'bar'), $handler->handle($connection, '2'));
@@ -60,7 +60,7 @@ class MultiBulkResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$this->assertNull($handler->handle($connection, '-1'));
}
@@ -77,7 +77,7 @@ class MultiBulkResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$handler->handle($connection, 'invalid');
}
@@ -28,7 +28,7 @@ class StatusResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$response = $handler->handle($connection, 'OK');
@@ -46,7 +46,7 @@ class StatusResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$response = $handler->handle($connection, 'QUEUED');
@@ -64,7 +64,7 @@ class StatusResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$response = $handler->handle($connection, 'Background saving started');
@@ -28,7 +28,7 @@ class StreamableMultiBulkResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$this->assertInstanceOf('Predis\Response\Iterator\MultiBulk', $handler->handle($connection, '1'));
}
@@ -45,7 +45,7 @@ class StreamableMultiBulkResponseTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->never())->method('readLine');
$connection->expects($this->never())->method('readBytes');
$connection->expects($this->never())->method('readBuffer');
$handler->handle($connection, 'invalid');
}
@@ -40,7 +40,7 @@ class ProtocolProcessorTest extends PredisTestCase
$connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
$connection->expects($this->once())
->method('writeBytes')
->method('writeBuffer')
->with($this->equalTo($serialized));
$protocol->write($connection, $command);