Client handles -NOSCRIPT falling back to EVAL for scripted commands.

Now Predis\Command\ScriptedCommand uses EVALSHA instead of EVAL internally
so that performances should be better since the client do not resend the
Lua script body on each call.

Plain EVALSHA commands are not affected and will return or throw the error.
This commit is contained in:
Daniele Alessandri
2012-04-28 08:42:58 +02:00
parent 75afe831b0
commit 2d0b30dac5
5 changed files with 62 additions and 7 deletions
+25
View File
@@ -643,6 +643,31 @@ class ClientTest extends StandardTestCase
$this->assertInstanceOf('Predis\Monitor\MonitorContext', $monitor = $client->monitor());
}
/**
* @group disconnected
*/
public function testClientResendScriptedCommandUsingEvalOnNoScriptErrors()
{
$command = $this->getMockForAbstractClass('Predis\Command\ScriptedCommand');
$command->expects($this->once())
->method('getScript')
->will($this->returnValue('return redis.call(\'exists\', KEYS[1])'));
$connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
$connection->expects($this->at(0))
->method('executeCommand')
->with($command)
->will($this->returnValue(new ResponseError('NOSCRIPT')));
$connection->expects($this->at(1))
->method('executeCommand')
->with($this->isInstanceOf('Predis\Command\ServerEval'))
->will($this->returnValue(true));
$client = new Client($connection);
$this->assertTrue($client->executeCommand($command));
}
// ******************************************************************** //
// ---- HELPER METHODS ------------------------------------------------ //
// ******************************************************************** //