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)