The manual learns that pipeline only sends out multiple REDIS instructions, and Redis does not guarantee that these specified executions are atomic; Multi is equivalent to a REDIS transaction, guaranteeing the atomicity of the entire operation, Avoid inconsistencies in the resulting data due to midway errors. The test is that the pipeline is more than 10 times times more efficient than the other way, enabling multi writing is slower than not opening.
On the code, looking for expert guidance.
<?PHPSet_time_limit(0);Ini_set(' Memory_limit ', ' 1024M ');$redis=NewRedis (); G (' 1 ');$redis->connect (' 127.0.0.1 ');//does not have atomicity, piping$redis-pipeline (); for($i= 0;$i<100000;$i++){ $redis->set ("test_{$i}",POW($i, 2)); $redis->get ("test_{$i}");}$redis-exec();$redis-Close (); G (' 1 ', ' e '); G (' 2 ');$redis->connect (' 127.0.0.1 ');//things have atomic$redis-multi (); for($i= 0;$i<100000;$i++){ $redis->set ("test_{$i}",POW($i, 2)); $redis->get ("test_{$i}");}$redis-exec();$redis-Close (); G (' 2 ', ' E ');//NormalG (' 3 ');$redis->connect (' 127.0.0.1 ');//things have atomic for($i= 0;$i<100000;$i++){ $redis->set ("test_{$i}",POW($i, 2)); $redis->get ("test_{$i}");}$redis-Close (); G (' 3 ', ' e ');functionG$star,$end= ' '){ Static $info=Array(); if(!Empty($end)) { $info[$end] =Microtime(true); $sconds=$info[$end] -$info[$star]; Echo $sconds, "ms<br/>"; } Else { $info[$star] =Microtime(true); }}
Results of the test output:
0.043839931488037ms
0.4456958770752ms
0.45916604995728ms
Multi and pipeline differences and efficiencies in Redis (recommended use of pipeline)