zoukankan      html  css  js  c++  java
  • cassandra CQL 常用操作

    1. CQL客户端链接

       bin/cqlsh ip username password 

    2. 

    (1)建立keyspace语句,keyspace类似于 mysql 中的数据库,一个数据库中可以有很多表;

    CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy','replication_factor' : 2 } ,replication_factor 表示 数据被复制几份

    (2)建表语句:

    CREATE TABLE task ( row_split text, column_split text, username text, parent_user text, priority int, url text, status int, is_dir boolean, channel_code text, is_multilayer boolean, action_type int, create_time bigint, finish_time bigint, id text, subtask_result text, reason text, retry_time int, PRIMARY KEY (row_split, column_split) ) ;  primary key 的第一个元素是rowkey,第二个元素的是cluster key;
     
    (3)建索引语句:
    create index task_status on task(status);  cassandra的索引不支持范围查找,类似于 位图索引 或者 哈希索引,支持 = 操作,不支持< 或 > 之类的范围查找;
     
    (4)查询语句,
    select * from task where status=2;
    注意,cassandra where 子句里面的,除了rowkey以外,其他字段如果要使用 = 操作,必须建立二级索引,而且cassandra里面的二级索引 不支持范围查询,类似于位图索引,不同于 BTREE索引;
     
    (5)删除语句,
    单独删除某个column 或者 某行;
    delete column1,column2 from table where rowkey = 'xxxx' 
    or 
    delete column1,column2 from table where rowkey in ('x','xx','xxx'...)
    其中where子句是不能省略的。
     
    (6)删除表中的所有数据
    如果要想实现 类似 mysql中 delete from table的效果,可以使用truncate;
     
    truncate table
  • 相关阅读:
    docker 基本概念
    6_State 游戏开发中使用状态机
    5_Singleton 游戏开发中的单例模式
    4_Prototype 原型
    3_observer
    2_flyweight, 轻量化模式
    1_Command 游戏开发命令模式
    CentOS7 Failed to start LSB: Bring up/down解决方法
    CentOS 7 中firewall-cmd命令
    CentOS查询端口占用和清除端口占用的程序
  • 原文地址:https://www.cnblogs.com/yuhan-TB/p/4745429.html
Copyright © 2011-2022 走看看