$redis->muti ($mode)->get ($key)->set ($key)->exec ();
Since this is the case, that is, when I want to use the pipeline to perform 10,000 operations, I need to write 10,000 operations at the back of Muti (),,, or do I find a better way of writing?
Didn't the designer think of that? The test was successful today.
[PHP]View Plaincopy
- <?
- php $redis = new Redis ();
- $redis->connect (' 10.1.132.86 ', 6379);
- $pipe = $redis->multi (redis::P ipeline);
- for ($i = 0; $i < 10000; $i + +) {
- $pipe->set ("key:: $i", str_pad ($i, 4, ' 0 ', 0));
- $pipe->get ("key:: $i");
- }
- $replies = exec () $pipe; echo ""; Print_r ($replies);
Description: Enter and exit transactional mode.
Parameters
(optional) Redis::MULTI
or Redis::PIPELINE
. Defaults to Redis::MULTI
. A Redis::MULTI
block of commands runs as a single transaction; a Redis::PIPELINE
block was simply transmitted faster to the server, but wit Hout any guarantee of atomicity. discard
Cancels a transaction.
Return Value
multi()
Returns the Redis instance and enters Multi-mode. Once in Multi-mode, all subsequent method calls return the same object until is exec()
called.
Example
$ret = $redis->multi() ->set(‘key1‘, ‘val1‘) ->get(‘key1‘) ->set(‘key2‘, ‘val2‘) ->get(‘key2‘) ->exec();/*$ret == array( 0 => TRUE, 1 => ‘val1‘, 2 => TRUE, 3 => ‘val2‘);*/
##############
Simple data mget can also be implemented
MGet, GetMultiple
Description: Get The values of all the specified keys. If one or more keys dont exist, the array would contain at the position of the FALSE
key.
Parameters
array: Array containing the list of keys
Return Value
array: Array containing the values related to keys in argument
Examples
$redis->set(‘key1‘, ‘value1‘);$redis->set(‘key2‘, ‘value2‘);$redis->set(‘key3‘, ‘value3‘);$redis->mGet(array(‘key1‘, ‘key2‘, ‘key3‘)); /* array(‘value1‘, ‘value2‘, ‘value3‘);$redis->mGet(array(‘key0‘, ‘key1‘, ‘key5‘)); /* array(`FALSE`, ‘value2‘, `FALSE`);
Faster execution with Redis pipeline in PHP