redis事务与watch

来源:互联网 发布:福昕pdf编辑器 mac 编辑:程序博客网 时间:2024/06/05 16:16
Jedis conn = new Jedis("localhost");conn.select(15);System.out.println(conn.get("key"));//watch要在事务开启前否则报错conn.watch("key");Transaction multi = conn.multi();multi.set("key", "124");Thread.sleep(10000);multi.hset("hkey", "name", "test1");multi.exec();System.out.println(conn.get("key"));//流水线 事务pipelined.watch()报错,还没找到原因Pipeline pipelined = conn.pipelined();conn.watch("key");//pipelined.watch("key");pipelined.multi();pipelined.set("key", "120");pipelined.hset("hkey", "name", "test");Thread.sleep(10000l);Response<List<Object>> exec = pipelined.exec();pipelined.sync();System.out.println(conn.get("key"));