Multi and pipeline differences and efficiencies in Redis (recommended use of pipeline)

Source: Internet
Author: User
Tags pow

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.