入门例子:
http://wiki.apache.org/cassandra/GettingStarted
添加环境变量并source生效,使得可以在任意位置执行cassandra/bin安装目录下的命令
1 |
export CASSANDRA_HOME="/Users/zhengqh/Soft/apache-cassandra-2.0.16" |
前台启动Cassandra进程, sudo cassandra -f
启动一个新的终端, 启动客户端查询: cqlsh
1 |
CREATE KEYSPACE mykeyspace |
输出:
cqlsh:mykeyspace> SELECT * FROM users WHERE lname = 'smith'; user_id | fname | lname
---------+-------+-------
| john | smith
| john | smith ( rows)
cqlsh:mykeyspace> SELECT * FROM users; user_id | fname | lname
---------+-------+-------
| john | smith
| john | doe
| john | smith ( rows)
观察服务端的输出:
1 |
INFO 09:29:21,981 Create new Keyspace: mykeyspace, rep strategy:SimpleStrategy{}, strategy_options: {replication_factor=1}, durable_writes: true |
然后看目录文件:
ls mykeyspace/users
结果:
mykeyspace-users-jb--CompressionInfo.db
mykeyspace-users-jb--Data.db
mykeyspace-users-jb--Filter.db
mykeyspace-users-jb-1-Index.db
mykeyspace-users-jb--Statistics.db
mykeyspace-users-jb--Summary.db
mykeyspace-users-jb--TOC.txt
mykeyspace-users.users_lname_idx-jb--CompressionInfo.db
mykeyspace-users.users_lname_idx-jb--Data.db
mykeyspace-users.users_lname_idx-jb--Filter.db
mykeyspace-users.users_lname_idx-jb-1-Index.db
mykeyspace-users.users_lname_idx-jb--Statistics.db
mykeyspace-users.users_lname_idx-jb--Summary.db
mykeyspace-users.users_lname_idx-jb--TOC.txt
如果是针对没有建立索引的字段搜索则会提示:
cqlsh:mykeyspace> SELECT * FROM users WHERE fname = 'smith';
InvalidRequest: Error from server: code= [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictab
le performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"