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即使用本地客户端内存,也用服务端内存,适合用实施性不高的场景