管道官方文档
https://redis.io/topics/pipelining
Maven依赖
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
java代码
public static void main(String[] args) {
Jedis jedis = new Jedis("127.0.0.1", 6390);
jedis.flushAll();
long startTime = System.currentTimeMillis();
for(int i=0; i<1000; i++) {
jedis.set("key", ""+i);
}
System.out.println("普通模式:" + (System.currentTimeMillis() - startTime));
jedis.flushAll();
//使用管道的测试
startTime = System.currentTimeMillis();
Pipeline pipeline = jedis.pipelined();
for(int i=0; i<1000; i++) {
pipeline.set("key", ""+i);
}
pipeline.sync();
System.out.println("管道模式:" + (System.currentTimeMillis() - startTime));
jedis.flushAll();
jedis.close();
}
结果:
明显管道比普通模式快了很多