Hector:高层次的Java Cassandra 客户端
Hector是一个高层次的Java Cassandra(非关系型数据库)客户端。
特性:
- 支持Failover
- 连接pooling
- 支持JMX
ps:Build之前需要先安装maven2.0
代码示例:
/**
* Insert a new value keyed by key
* @param key Key for the value
* @param value the String value to insert
*/
public void insert(final String key, final String value) throws Exception {
execute(new Command(){
public Void execute(final Keyspace ks) throws Exception {
ks.insert(key, createColumnPath(COLUMN_NAME), bytes(value));
return null;
}
});
}
/**
* Get a string value.
* @return The string value; null if no value exists for the given key.
*/
public String get(final String key) throws Exception {
return execute(new Command(){
public String execute(final Keyspace ks) throws Exception {
try {
return string(ks.getColumn(key, createColumnPath(COLUMN_NAME)).getValue());
} catch (NotFoundException e) {
return null;
}
}
});
}
/**
* Delete a key from cassandra
*/
public void delete(final String key) throws Exception {
execute(new Command(){
public Void execute(final Keyspace ks) throws Exception {
ks.remove(key, createColumnPath(COLUMN_NAME));
return null;
}
});
}
点击查看详情:
下一篇: 初学Unity 3D 碰到的语句