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"));
redis事务与watch
最新推荐文章于 2024-10-11 09:07:53 发布