无pipeline
* 10000 耗时:843ms
* 100000 耗时:8085ms
有pipeline
* 10000 耗时:74ms
* 100000 耗时:405ms
@BeforeEach
public void start() {
start = System.currentTimeMillis();
System.out.println("@Before");
}
/**
* 无pipeline 耗时:843ms
*/
@Test
public void testNoPipeline() {
//连接redis服务器,192.168.0.100:6379
Jedis jedis = new Jedis("127.0.0.1", 6379);
jedis.auth("123456");
List nameList = Arrays.asList("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
int len = nameList.size();
for (int i = 0; i < 10000; i++) {
int index = i % len;
jedis.set(i + "", nameList.get(index));
}
jedis.close();
System.out.println("testNoPipeline结束");
}
/**
* 有pipeline 耗时:74ms
*/
@Test
public void testPipeline() {
//连接redis服务器,192.168.0.100:6379
Jedis jedis = new Jedis("127.0.0.1", 6379);
jedis.auth("123456");
Pipeline pipeline = jedis.pipelined();
List nameList = Arrays.asList("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
int len = nameList.size();
for (int i = 0; i < 10000; i++) {
int index = i % len;
pipeline.mset(i + "", nameList.get(index));
}
// 同步
pipeline.sync();
jedis.close();
System.out.println("testPipeline结束");
}
@AfterEach
public void end() {
System.out.println("@After");
end = System.currentTimeMillis();
System.out.println( "耗时:" + (end - start) + "ms");
}