cassandra get set同步問題
import quicktime.std.clocks.Clock;
import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.ColumnQuery;
import me.prettyprint.hector.api.query.QueryResult;
public class ExampleClient {
public static void main(String[] args) throws IllegalStateException,Exception {
CassandraHostConfigurator cassandraHostConfigurator=new CassandraHostConfigurator("192.168.100.108:9160,192.168.100.110:9160");
cassandraHostConfigurator.setMaxActive(20);
cassandraHostConfigurator.setMaxIdle(5);
cassandraHostConfigurator.setCassandraThriftSocketTimeout(3000);
cassandraHostConfigurator.setMaxWaitTimeWhenExhausted(4000);
StringSerializer stringSerializer=new StringSerializer();
Cluster cluster=HFactory.createCluster("cluster_name", cassandraHostConfigurator);
Keyspace ks=HFactory.createKeyspace("OBS", cluster);
String columnFamily = "bucket";
Mutator
mutator.insert("bucket_key", columnFamily, HFactory.createStringColumn("object_name", "object_value"));
ColumnQuery
columnQuery.setColumnFamily(columnFamily).setKey("bucket_key").setName("object_name");
QueryResult
//若物件存在,列印物件key-value
System.out.println("object_name: "+queryResult.get().getName());
System.out.println("object_value: "+queryResult.get().getValue());
System.out.println("object_clock: "+queryResult.get().getClock());
//測試一個不存在的物件
System.out.println("測試一個不存在的物件");
columnQuery.setColumnFamily(columnFamily).setKey("bucket_key").setName("object_name1");
queryResult=columnQuery.execute();
try{
System.out.println("queryResult: "+queryResult.get().getClock());
}catch(NullPointerException e){
System.out.println("the object you query does not exist!");
e.printStackTrace();
}
//測試獲取一個刪除的物件
System.out.println("測試一個刪除的物件");
columnQuery.setColumnFamily(columnFamily).setKey("bucket_name").setName("object_name");
queryResult=columnQuery.execute();
try{
System.out.println("queryResult: "+queryResult.get().getClock());
}catch(NullPointerException e){
System.out.println("the object you query does not exist!");
e.printStackTrace();
}
//測試寫入一個物件後,在寫入一個比當前物件時間戳要小的物件
//exist object_name_tw object_value_tw 1310661932412000L
long clock =1210661994080000L;
//mutator.insert("bucket_key", columnFamily, HFactory.createStringColumn("object_name_tw", "object_value_tw"));
HColumn
mutator.insert("bucket_key", columnFamily, column);
cluster.getConnectionManager().shutdown();
//result:clock 小於當前物件 則當前物件仍保留;clock大於當前物件,新的物件被寫入
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23937368/viewspace-1052469/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Lombok生成get/set異常問題(Lombok缺陷)Lombok
- lombok get/set 與 JavaBean get/setLombokJavaBean
- javascript get和set訪問器JavaScript
- JavaScript get set 訪問器屬性JavaScript
- cassandra&hector版本問題
- C# Get SetC#
- 淺說 get set
- PHP memcached,(set,get)PHP
- python:get和setPython
- 快速生成get、set方法
- 原型鏈上的get與set訪問器屬性原型
- javascript 物件屬性的get set訪問器寫法JavaScript物件
- 初學 PHP __set ( ) 和 __ get ( )PHP
- 同時重寫屬性的get和set方法系統報錯問題處理
- c#索引訪問器再探_get_set之訪問控制存取C#索引
- 測試CMS同步問題測試CMS同步問題
- python set和get實現Python
- How to get and set the system socket buffer in AIXAI
- jive 同步問題
- C#中類的屬性訪問器--get和set分析C#
- 私有屬性的Get Set 與 Public
- Get Set Up to Help With Python Core DevelopmentPythondev
- Swift 成員變數的get/setSwift變數
- ogg 同步問題
- Get 所有 Redis 效能問題分析手段Redis
- 解決 go get 超時問題Go
- docker apt-get 換源問題Dockerapt-get
- PHP 分散式memcached伺服器 set,getPHP分散式伺服器
- 分類不能自動建立 get set 方法
- Objective-C中get/set方法初探(1)Object
- Objective-C中get/set方法初探(2)Object
- cassandra業務資料一致性問題處理?
- 解決set newname 極慢的問題
- 快取同步的問題快取
- 資料庫同步問題資料庫
- c# public_protected_private許可權訪問符_屬性訪問器get_setC#
- XHR 例項 GET 和 POST 非同步和同步非同步
- 前端面試:js同步與非同步問題前端面試JS非同步