diff --git a/test/PredisShared.php b/test/PredisShared.php index 6f52c741..52efa5d6 100644 --- a/test/PredisShared.php +++ b/test/PredisShared.php @@ -21,6 +21,7 @@ class RC { const EXCEPTION_NO_SUCH_KEY = 'no such key'; const EXCEPTION_OUT_OF_RANGE = 'index out of range'; const EXCEPTION_INVALID_DB_IDX = 'invalid DB index'; + const EXCEPTION_EXEC_NO_MULTI = 'EXEC without MULTI'; private static $_connection; diff --git a/test/RedisCommandsTest.php b/test/RedisCommandsTest.php index ed637df0..49b21224 100644 --- a/test/RedisCommandsTest.php +++ b/test/RedisCommandsTest.php @@ -45,6 +45,25 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase { $this->assertFalse($this->redis->isConnected()); } + function testMultiExec() { + // NOTE: due to a limitation in the current implementation of Predis\Client, + // the replies returned by Predis\Command\Exec are not parsed by their + // respective Predis\Command::parseResponse methods. If you need that + // kind of behaviour, you should use an instance of Predis\MultiExecBlock. + $this->assertTrue($this->redis->multi()); + $this->assertType('Predis\ResponseQueued', $this->redis->ping()); + $this->assertType('Predis\ResponseQueued', $this->redis->echo('hello')); + $this->assertType('Predis\ResponseQueued', $this->redis->echo('redis')); + $this->assertEquals(array('PONG', 'hello', 'redis'), $this->redis->exec()); + + $this->assertTrue($this->redis->multi()); + $this->assertEquals(array(), $this->redis->exec()); + + // should throw an exception when trying to EXEC without having previously issued MULTI + RC::testForServerException($this, RC::EXCEPTION_EXEC_NO_MULTI, function($test) { + $test->redis->exec(); + }); + } /* commands operating on string values */