Jedis之pipeline

前端之家收集整理的这篇文章主要介绍了Jedis之pipeline前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Pipeline
官方的说明是:starts a pipeline,which is a very efficient way to send lots of command and read all the responses when you finish sending them。简单点说pipeline适用于批处理。当有大量的操作需要一次性执行的时候,可以用管道。
示例:
Jedisjedis= newJedis(String,int);
Pipelinep=jedis.pipelined();
p.set(key,value); //每个操作 都发送请求给redis-server
p.get(key,value);

p.sync(); // 这段代码获取所有的response

这里我进行了20w次连续操作(10w读,10w写),不用pipeline耗时:187242ms,用pipeline耗时:1188ms,可见使用管道后的性能上了一个台阶。看了代码了解到,管道通过一次性写入请求,然后一次性读取响应。也就是说jedis是:request response,request response,...;pipeline则是:request request... response response的方式。这样无需每次请求都等待server端的响应。

原文如下:http://www.blogjava.net/masfay/archive/2012/07/03/382080.html

原文链接:https://www.f2er.com/javaschema/286138.html

猜你在找的设计模式相关文章