ITPub博客

首页 > IT职业 > IT生活 > 看了四个小时hector guide,借用一个hector的使用清单来总结下hector的使用

看了四个小时hector guide,借用一个hector的使用清单来总结下hector的使用

原创 IT生活 作者:oxoxooxx 时间:2011-05-29 21:54:36 0 删除 编辑

import static me.prettyprint.cassandra.utils.StringUtils.bytes;
import static me.prettyprint.cassandra.utils.StringUtils.string;
import org.apache.cassandra.service.Column;
import org.apache.cassandra.service.ColumnPath;

public class ExampleClient {
public static void main(String[] args) throws IllegalStateException,
PoolExhaustedException, Exception {
CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get();
CassandraClient client = pool.borrowClient("localhost", 9160);
// A load balanced version would look like this:
// CassandraClient client = pool.borrowClient(new String[] {"cas1:9160",
// "cas2:9160", "cas3:9160"});
try {
Keyspace keyspace = client.getKeyspace("Keyspace1");
ColumnPath columnPath = new ColumnPath("Standard1", null,
bytes("网址"));
// insert
keyspace.insert("逖靖寒的世界", columnPath,
bytes("http://gpcuster.cnblogs.com"));
// read
Column col = keyspace.getColumn("逖靖寒的世界", columnPath);
System.out
.println("Read from cassandra: " + string(col.getValue()));
} finally {
// return client to pool. do it in a finally block to make sure it's
// executed
pool.releaseClient(client);
}
}
}

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23937368/viewspace-1050522/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    178
  • 访问量
    843653