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

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博客 ” ,链接:http://blog.itpub.net/23937368/viewspace-1050522/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23937368/viewspace-1050522/

你可能感兴趣的:(看了四个小时hector guide,借用一个hector的使用清单来总结下hector的使用)