Jedis干什么用的

如题所述

Jedis使用总结
前段时间细节的了解了Jedis的使用,Jedis是redis的java版本的客户端实现。
本文做个总结,主要分享如下内容:
【pipeline】【分布式的id生成器】【分布式锁【watch】【multi】】【redis分布式】
好了,一个一个来。
一、 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适用于批处理。当有大量的操作需要一次性执行的时候,可以用管道。
示例:
Jedis jedis = new Jedis(String, int);
Pipeline p = 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端的响应。
二、 跨jvm的id生成器
温馨提示:答案为网友推荐,仅供参考
相似回答