Jedis jedis0 = new Jedis("localhost", 6379);
jedis0.auth("123456");
Pipeline pipelined = jedis0.pipelined();
Set<String> keys = jedis0.keys("batch*");
for (String key:keys){
pipelined.get(key);
}
List<Object> objects = pipelined.syncAndReturnAll();
long l1 = System.currentTimeMillis();
for (Object src:objects){
System.out.println(src);
}
long l2 = System.currentTimeMillis();
System.out.println("耗時:"+(l2-l1)+"ms");
}
使用Pipeline百萬級數據7
Jedis jedis0 = new Jedis("localhost", 6379);
jedis0.auth("123456");
long l1 = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
jedis0.get("batch" + i);
}
long l2 = System.currentTimeMillis();
System.out.println("耗時:" + (l2 - l1) + "ms");
普通get去獲取耗時:耗時:48622ms
前提redis版本要支持緩存,redis源碼每次緩存8192個字節,
# client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>超過這個限制直接斷開連接,不然存了
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

obl:輸出緩存區長度
oll: 使用緩存的數量
omen:obl和oll占用的內內存
使用時要控制內存,因為使用Pipeline即使用本地客戶端內存,也用服務端內存,適合用實施性不高的場景
