赞
踩
接上例:http://blog.csdn.net/kunshan_shenbin/article/details/7101016
除了Hector以外,基于Java的cassandra的客户端还有很多,Pelops就是其中之一。
官方网址:http://code.google.com/p/pelops/
参考网站:
http://gigi-112.iteye.com/blog/757488
http://ria101.wordpress.com/2010/06/11/pelops-the-beautiful-cassandra-database-client-for-java/
测试代码如下:
- import org.apache.cassandra.thrift.Column;
- import org.apache.cassandra.thrift.ConsistencyLevel;
- import org.scale7.cassandra.pelops.Cluster;
- import org.scale7.cassandra.pelops.Mutator;
- import org.scale7.cassandra.pelops.Pelops;
- import org.scale7.cassandra.pelops.Selector;
-
- public class PelopsClient {
-
- public static void main(String[] args) {
-
- Cluster cluster = new Cluster("192.168.11.124", 9160);
- Pelops.addPool("Main", cluster, "LiftDNA_DB");
-
- Mutator mutator = Pelops.createMutator("Main");
- Column newColumn = mutator.newColumn("age", "30");
- mutator.writeColumn("LiftDNA_Table", "shenbin", newColumn);
- mutator.execute(ConsistencyLevel.ONE);
-
- Selector selector = Pelops.createSelector("Main");
- Column column = selector.getColumnFromRow("LiftDNA_Table", "shenbin", "age", ConsistencyLevel.ONE);
- System.out.println(new String(column.getValue()));
-
- mutator.deleteColumn("LiftDNA_Table", "shenbin", "age");
- mutator.execute(ConsistencyLevel.ONE);
- }
- }
需要用到的lib有:
apache-cassandra-thrift-1.0.6.jar
commons-pool-1.5.7.jar
guava-r09.jar
libthrift-0.6.1.jar
slf4j-api-1.6.1.jar
uuid-3.2.0.jar
此外,当然还少不了pelops,可以在这里下载到它:https://github.com/s7(scale7-core + scale7-pelops)
其他语言:
http://wiki.apache.org/cassandra/ThriftExamples
另外,还有很多其他的第三方客户端实现,
譬如 Kundera : https://github.com/impetus-opensource/Kundera
http://code.google.com/p/jassandra/
其他资料,参看这里:http://code.google.com/hosting/search?q=label:Cassandra
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。