首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

Cassandra数据储存

2012-07-03 
Cassandra数据存储版本:0.7.6客户端:cassandra自带的thrift客户端标准column的查询、删除、新增://删除数据

Cassandra数据存储

版本:0.7.6

客户端:cassandra自带的thrift客户端

标准column的查询、删除、新增:


//删除数据
// path = new ColumnPath();
// path.setColumn_family("standard1");
// path.setColumn("age".getBytes("UTF-8"));
// client.remove(ByteBuffer.wrap("user".getBytes()), path, timestamp, ConsistencyLevel.ONE);

// 关闭数据库连接
tr.close();

?SuperColumn新增和查询:

/** * 插入SuperColumn *  * @throws Exception */public void insertSuperColumn() throws Exception {TTransport tr = new TFramedTransport(new TSocket("localhost",9160)); TProtocol proto = new TBinaryProtocol(tr);  Cassandra.Client client = new Cassandra.Client(proto);  tr.open();  client.set_keyspace("Keyspace1");ColumnParent cp1 = new ColumnParent();cp1.setColumn_family("Super2");cp1.setSuper_column("address".getBytes());Column city = new Column();city.setName("province".getBytes());city.setValue("guangdong".getBytes());city.setTimestamp(time);client.insert(ByteBuffer.wrap("user2".getBytes()), cp1, city, ConsistencyLevel.ONE);}/** * 读取SuperColumn *  * @throws Exception */public void getSuper() throws Exception {TTransport tr = new TFramedTransport(new TSocket("localhost",9160)); TProtocol proto = new TBinaryProtocol(tr);  Cassandra.Client client = new Cassandra.Client(proto);  tr.open();  client.set_keyspace("Keyspace1");ColumnPath path = new ColumnPath("Super2");path.setSuper_column("address".getBytes());path.setColumn("province".getBytes());ColumnOrSuperColumn s = client.get(ByteBuffer.wrap("user5".getBytes()), path, ConsistencyLevel.ONE);System.out.println(new String(s.column.getValue(), "utf8"));}

?困惑:如果superColumn下的Column是一个SuperColumn怎么插入数据?没有找到相关的api。

热点排行