123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- require 'SharedConfigurations.php';
- use Predis\Command\ScriptedCommand;
- class IncrementExistingKeysBy extends ScriptedCommand
- {
- public function getKeysCount()
- {
-
-
- return -1;
- }
- public function getScript()
- {
- return
- <<<LUA
- local cmd, insert = redis.call, table.insert
- local increment, results = ARGV[1], { }
- for idx, key in ipairs(KEYS) do
- if cmd('exists', key) == 1 then
- insert(results, idx, cmd('incrby', key, increment))
- else
- insert(results, idx, false)
- end
- end
- return results
- LUA;
- }
- }
- $client = new Predis\Client($single_server);
- $client->getProfile()->defineCommand('increxby', 'IncrementExistingKeysBy');
- $client->mset('foo', 10, 'foobar', 100);
- var_export($client->increxby('foo', 'foofoo', 'foobar', 50));
|