一、简介
http://cassandra.apache.org/doc/latest/
二、下载地址
http://www.apache.org/dyn/closer.lua/cassandra/2.2.8/apache-cassandra-2.2.8-bin.tar.gz
三、启动
1)进入~/apache-cassandra-2.2.8/bin 目录:
命令 | 备注 |
---|---|
./cassandra | 启动 |
./cqlsh localhost | 连接cassandra |
2)执行./cassandra
启动命令:
1 | ➜ bin ./cassandra |
3)执行 ./cqlsh localhost
命令:
1 | ➜ bin ./cqlsh localhost |
四、Java API
1) 创建 keyspace
1 | CREATE KEYSPACE demodb WITH REPLICATION = {'class' : 'SimpleStrategy','replication_factor': 3}; |
2) 创建 table
1 | CREATE TABLE users ( |
3) 插入数据
1 | INSERT INTO users (user_name, password, gender) VALUES ('zhengyong', '1234', 'male'); |
4) Java查询
参考:https://github.com/datastax/java-driver
手册:http://docs.datastax.com/en/developer/java-driver/3.1/manual/
maven依赖
1 | <dependency> |
cassandra客户端:
1 | package cassandra; |
运行main函数:
1 | package cassandra; |
运行结果:
1 | 2016-12-12 23:43:21,812 - com.datastax.driver.core.ClockFactory -0 [main] INFO - Using native clock to generate timestamps. |
1 | ➜ bin ./cqlsh localhost |
CREATE TABLE users (
username varchar,
password varchar,
gender varchar,
PRIMARY KEY (username));