Redis client 2.0.0 pipeline list rpop bug, redisrpop
Description:
The rpop of the list OF redis client 2.0.0 pipeline has a serious bug. When the rpop list is used, if the list is already empty, the Response from rpop is still not null, causing the listresponse to be suspended. the get () method throws an exception.
Code:
@Testpublic void testRedisPipeline(){ Jedis jedis = null; try{ jedis = new Jedis("127.0.0.1",6379); Pipeline pipelined = jedis.pipelined(); for(int i=200;i<10000;i++){ pipelined.lpush("aa", "val"+i); } pipelined.sync(); }catch(Exception e){ e.printStackTrace(); }finally{ if(jedis!=null){ jedis.disconnect(); } }}
<Span style = "white-space: pre"> </span> // This method causes redis qps to rise infinitely @ Testpublic void testRedisPipelinePop () {Jedis jedis = null; try {List <Response <String> result = new ArrayList <Response <String> (); jedis = new Jedis ("127.0.0.1", 6379); Pipeline pipelined = jedis. pipelined (); for (int I = 0; I <10; I ++) {// System. out. println (I); Response <String> rpop = pipelined. rpop ("aa"); // System. out. println (rpop); result. add (Rpop);} pipelined. sync (); // Response <Long> r = pipelined. bitcount ("aa"); for (Response <String> response: result) {System. out. println (response. get (); // Exception} catch (Exception e) {e. printStackTrace ();} finally {if (jedis! = Null) {jedis. disconnect ();}}}
Solution:
Use redis-cli 2.1.0 or later