Cassandra 基本操作

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).

 

转载于:https://www.cnblogs.com/kenshinn/p/4732843.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值