天天看點

cassandra hector 安裝與測試

1,從  https://github.com/rantav/hector/downloads 下載下傳hector-core-0.7.0-31

2,建立項目,将hector-core-0.7.0-31中的jar導入項目中

3,測試代碼:

Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "10.10.246.122:9160");

            Keyspace keyspace =  HFactory.createKeyspace("myspace1", cluster);

            ColumnFamilyDefinition cf = HFactory.createColumnFamilyDefinition("myspace1","user",ComparatorType.UTF8TYPE);

            StringSerializer stringSerializer = StringSerializer.get();

            Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);

            mutator.insert("122", "user", HFactory.createStringColumn("first", "John"));

4,登陸伺服器,指令查詢:

use myspace1

get user['122']

顯示剛插入的資料