Cassandra version: apache-cassandra-2.1.3
OS: Ubuntu 14.10
进入cassandra命令行
$./cassandra-cli
查看节点状态
$ ./nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns Host ID Rack
UN 127.0.0.1 71.23 KB 256 ? 61129023-a5c0-4331-98ce-7cb24d6ddb28 rack1
Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless
创建Keyspace:
[default@unknown] create keyspace mykeyspace with strategy_options={replication_factor:1} and placement_strategy ='org.apache.cassandra.locator.SimpleStrategy';
进入刚刚创建的keyspace:
[default@unknown] use mykeyspace;
创建一个列簇
[default@mykeyspace] create column family User;
查看keyspace的详细信息
[default@mykeyspace] describe mykeyspace;
WARNING: CQL3 tables are intentionally omitted from 'describe' output. See https://issues.apache.org/jira/browse/CASSANDRA-4377 for details. Keyspace: mykeyspace: Replication Strategy: org.apache.cassandra.locator.SimpleStrategy Durable Writes: true Options: [replication_factor:1] Column Families: ColumnFamily: User Key Validation Class: org.apache.cassandra.db.marshal.BytesType Default column value validator: org.apache.cassandra.db.marshal.BytesType Cells sorted by: org.apache.cassandra.db.marshal.BytesType GC grace seconds: 864000 Compaction min/max thresholds: 4/32 Read repair chance: 0.0 DC Local Read repair chance: 0.1 Caching: KEYS_ONLY Default time to live: 0 Bloom Filter FP chance: default Index interval: default Speculative Retry: NONE Built indexes: [] Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy Compression Options: sstable_compression: org.apache.cassandra.io.compress.LZ4Compressor
插入一行数据
[default@mykeyspace] set User['me']['fname']='Lynch';
org.apache.cassandra.serializers.MarshalException: cannot parse 'fname' as hex bytes
报错了, 汗.
解决:
[default@mykeyspace] set User[ascii('me')][ascii('fname')]=ascii('Lynch');
Value inserted.
Elapsed time: 133 msec(s).
查询column的行数
[default@mykeyspace] count User[ascii('me')];
2 cells
查询某个column family的值
[default@mykeyspace] get User[ascii('me')];
=> (name=656d61696c, value=lynch@gmail.com, timestamp=1437685470045000)
=> (name=666e616d65, value=Lynch, timestamp=1437685481604000)
Returned 2 results.
Elapsed time: 31 msec(s).
删除一行:
[default@mykeyspace] del User[ascii('me')][ascii('email')];
cell removed.
Elapsed time: 32 msec(s).
[default@mykeyspace] get User[ascii('me')];
=> (name=666e616d65, value=Lynch, timestamp=1437685481604000)
Returned 1 results.
Elapsed time: 2.78 msec(s).