12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- require 'SharedConfigurations.php';
- use Predis\Command\ScriptedCommand;
- class IncrementExistingKey extends ScriptedCommand
- {
- public function getKeysCount()
- {
- return 1;
- }
- public function getScript()
- {
- return
- <<<LUA
- local cmd = redis.call
- if cmd('exists', KEYS[1]) == 1 then
- return cmd('incr', KEYS[1])
- end
- LUA;
- }
- }
- $client = new Predis\Client($single_server, '2.6');
- $client->getProfile()->defineCommand('increx', 'IncrementExistingKey');
- $client->set('foo', 10);
- var_dump($client->increx('foo'));
- var_dump($client->increx('bar'));
|