入門例子:
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 ---------+-------+------- 1745 | john | smith 1746 | john | smith (2 rows) cqlsh:mykeyspace> SELECT * FROM users; user_id | fname | lname ---------+-------+------- 1745 | john | smith 1744 | john | doe 1746 | john | smith (3 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-1-CompressionInfo.db mykeyspace-users-jb-1-Data.db mykeyspace-users-jb-1-Filter.db mykeyspace-users-jb-1-Index.db mykeyspace-users-jb-1-Statistics.db mykeyspace-users-jb-1-Summary.db mykeyspace-users-jb-1-TOC.txt mykeyspace-users.users_lname_idx-jb-1-CompressionInfo.db mykeyspace-users.users_lname_idx-jb-1-Data.db mykeyspace-users.users_lname_idx-jb-1-Filter.db mykeyspace-users.users_lname_idx-jb-1-Index.db mykeyspace-users.users_lname_idx-jb-1-Statistics.db mykeyspace-users.users_lname_idx-jb-1-Summary.db mykeyspace-users.users_lname_idx-jb-1-TOC.txt
如果是針對沒有建立索引的字段搜索則會提示:
cqlsh:mykeyspace> SELECT * FROM users WHERE fname = 'smith'; InvalidRequest: Error from server: code=2200 [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"