public void testName() throws Exception { Jedis jedis=new Jedis("192.168.200.128"); jedis.watch("num");//监视num String string = jedis.get("num"); Transaction transaction = jedis.multi();//开启事务 int num=Integer.parseInt(string); if(num>0){ transaction.decr("num");//修改num-1 List<Object> exec = transaction.exec();//提交事务 if(exec==null){//num被修改返回null System.out.println("修改失败"); }else{ System.out.println("成功"); } }else{ System.out.println("失败"); } jedis.close(); }