`

cassandra

 
阅读更多

cassandra 客户端命令操作流程:

 

具体流程:

首先,启动cassandra:

进入安装目录,使用命令:bin/cassandra

然后,连接到一个节点上

 
$ ./cassandra-cli -host localhost -port 9160
  
Connected to: "Test Cluster" on localhost/9160
  
Welcome to cassandra CLI.
  
Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit.

之后创建一个key space和CF

 
 
[default@unknown] create keyspace twissandra with replication_factor=1
  
and placement_strategy='org.apache.cassandra.locator.SimpleStrategy';
  
[default@unknown] use twissandra;
  
Authenticated to keyspace: twissandra
  
------------
  
... schemas agree across the cluster
  
[default@twissandra]  create column family users with comparator = UTF8Type;
  
c21f48d5-8748-11e0-8afd-e700f669bcfc
  
Waiting for schema agreement...
  
... schemas agree across the cluster
  
[default@twissandra] set users['Bob']['phone']='1251892983';
  
Value inserted.
  
[default@twissandra] set users['Bob']['address']='Haidian,Beijing';
  
Value inserted.
  
[default@twissandra] set users['Bob']['birthday']='1980-08-09';
  
Value inserted.
  
[default@twissandra] get users['Bob'];
  
=> (column=address, value=4861696469616e2c4265696a696e67, timestamp=1306380804182000)
  
=> (column=birthday, value=313938302d30382d3039, timestamp=1306380831152000)
  
=> (column=phone, value=31323531383932393833, timestamp=1306380777399000)
  
Returned 3 results.

更新phone column的值

 
[default@twissandra]  set users['Bob']['phone']='1251892999';
  
Value inserted.

删除phone column

 
[default@twissandra] del  users['Bob']['phone'];
  
column removed.
  
[default@twissandra] list users;
  
Using default limit of 100
  
-------------------
  
RowKey: Bob
  
=> (column=adress, value=4861696469616e2c4265696a696e67, timestamp=1306380804182000)
  
=> (column=birthday, value=313938302d30382d3039, timestamp=1306380831152000)

删除users CF

 
[default@twissandra] drop column family users;
  
f1d9d7a6-874a-11e0-8afd-e700f669bcfc
  
Waiting for schema agreement...
  
... schemas agree across the cluster
  
------

创建SCF

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[default@twissandra] create column family friends with column_type=Super;
  
73264792-8740-11e0-8afd-e700f669bcfc
  
Waiting for schema agreement...
  
... schemas agree across the cluster
  
[default@twissandra] set friends['Bob']['address']['family']='BeiJing';
  
Value inserted.
  
[default@twissandra] set friends['Bob']['address']['company']='BeiJing';
  
Value inserted.
  
[default@twissandra] get friends['Bob']['address'];
  
=> (column=636f6d70616e79, value=4265694a696e67, timestamp=1306380530572000)
  
=> (column=66616d696c79, value=4265694a696e67, timestamp=1306380522162000)
  
Returned 2 results.
  
[default@twissandra] get friends['Bob'];
  
=> (super_column=61646472657373,
  
(column=636f6d70616e79, value=4265694a696e67, timestamp=1306380530572000)
  
(column=66616d696c79, value=4265694a696e67, timestamp=1306380522162000))
  
Returned 1 results。
分享到:
评论
Global site tag (gtag.js) - Google Analytics