1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- require 'SharedConfigurations.php';
- use Predis\Commands\ScriptedCommand;
- class IncrementExistingKey extends ScriptedCommand
- {
- protected function keysCount()
- {
- 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, 'dev');
- $client->getProfile()->defineCommand('increx', 'IncrementExistingKey');
- $client->set('foo', 10);
- var_dump($client->increx('foo'));
- var_dump($client->increx('bar'));
|