Redis-pipelining (pipe)

Source: Internet
Author: User

The client sends a query request to the server and listens for the socket return, waiting for the server to respond. Typically, blocking mode is suspended until the server response is received and cannot continue sending requests.

you can use pipelines to improve this situation. in the case of pipelines, the client can request the server regardless of whether the server has a reply. This makes it possible to issue multiple commands at once.

The following is a comparison of the time it takes to send a series of requests after the Jedis is in general and when the pipeline is opened.

 Public classPipelinetest { Public Static voidMain (string[] args) {Jedis Jedis=NewJedis ("127.0.0.1", 6379);        Withoutpipeline (Jedis);            Withpipeline (Jedis); }        Private Static voidwithoutpipeline (Jedis Jedis) {LongStart =System.currenttimemillis (); Jedis.set ("Name", "GPF");  for(inti = 0; i < 1000; i++) {jedis.append ("Name", "X"); }        LongEnd =System.currenttimemillis ();        Jedis.disconnect (); System.out.println ("Time Withoutpipeline:" + (end-start)); System.out.println (Jedis.get ("Name")); }        Private Static voidwithpipeline (Jedis Jedis) {LongStart =System.currenttimemillis (); Jedis.set ("Name", "GPF"); Pipeline PL=jedis.pipelined ();  for(inti = 0; i < 1000; i++) {pl.append ("Name", "Y");        } pl.sync (); LongEnd =System.currenttimemillis (); System.out.println ("Time Withpipeline:" + (end-start)); System.out.println (Jedis.get ("Name")); }}

The results of multiple tests are as follows:

Time withoutpipeline:158gpfxxxxxxxxxxxxxxxxxxxxx...time withpipeline:gpfyyyyyyyyyyyyyyyyyyyyy ... 

As you can see, the efficiency increases significantly after opening the pipe.

Redis-pipelining (pipe)

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.