CAS
checkAndPut
其中,put方法的最后一个参数是你需要录入的数据的put对象;
value是与服务端check的预期值,只有服务器端对应rowkey的数据与你预期的值相同时,你的put操作才能被提交的服务端。
Table table = conn.getTable(TableName.valueOf("t_user_info"));
Put put = new Put(Bytes.toBytes("liu_sh_01"));
put.add(Bytes.toBytes("base_info"), Bytes.toBytes("username"), Bytes.toBytes("jdxia"));
//这个值是否等于helloworld,等于的话就执行put
boolean b = table.checkAndPut(Bytes.toBytes("liu_sh_01"), Bytes.toBytes("base_info"),
Bytes.toBytes("username"), Bytes.toBytes("helloworld"), put);
//是否有值
// boolean b = table.checkAndPut(Bytes.toBytes("liu_sh_01"), Bytes.toBytes("base_info"),
// Bytes.toBytes("username"), null, put);
//看看是否执行了put
System.out.println(b);
table.close();
checkAndDelete
Table table = conn.getTable(TableName.valueOf("t_user_info"));
Delete delete = new Delete(Bytes.toBytes("liu_sh_01"));
delete.deleteColumns(Bytes.toBytes("base_info"), Bytes.toBytes("username"));
//这个值是否等于helloworld,等于的话就执行
boolean b = table.checkAndDelete(Bytes.toBytes("liu_sh_01"), Bytes.toBytes("base_info"),
Bytes.toBytes("username"), Bytes.toBytes("jdxia"), delete);
//看看是否执行了
System.out.println(b);
table.close();