Cassandra simple insert/get 하기..

Client 객체는 기본적으로, 카산드라 클라이언트(Cassandra.Client) 생성 예제를 같이 사용하고 있습니다.
가장 기초적인 1개의 Column에 데이타 insert/get 하는 예제입니다..

package net.sjava.cassandra.test;import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnPath;
import org.apache.cassandra.thrift.ConsistencyLevel;

public class CassandraTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

CassandraClientFactory factory = CassandraClientFactory.getInstance();
String keyspace = “Keyspace1”;
String columnFamily = “Standard2”;
String key = “key1″;
long timestamp = System.currentTimeMillis();

String value =”aaaaaaaaaaaaaaaaaaa_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb”;
try {
ColumnPath cPath = new ColumnPath(columnFamily);
cPath.setColumn(“name”.getBytes(“utf-8”));
factory.getClient().insert(keyspace, key, cPath, value.getBytes(“utf-8”), timestamp, ConsistencyLevel.ONE);
Column col = factory.getClient().get(keyspace, key, cPath, ConsistencyLevel.ONE).getColumn();
System.out.println(“Column name: ” + new String(col.name, “utf-8”));
System.out.println(“Column value: ” + new String(col.value, “utf-8″));

value =”aaaaaaaaaa”;

long time2 = System.currentTimeMillis();
factory.getClient().insert(keyspace, key, cPath, value.getBytes(“utf-8”), time2, ConsistencyLevel.ONE);
Column col2 = factory.getClient().get(keyspace, key, cPath, ConsistencyLevel.ONE).getColumn();
System.out.println(“Column2 name: ” + new String(col2.name, “utf-8”));
System.out.println(“Column2 value: ” + new String(col2.value, “utf-8”));
} catch(Exception e) {
e.printStackTrace();
}
}
}

 

Cassandra simple insert/get 하기..”에 대한 2개의 생각

답글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.