一般的网站介绍Cassandra入门都是写:
set Keyspace1.Standard2['studentA']['age'] = '18'
要注意的是,刚开始Keyspace1.Standard2是不存在或者没有用命令指定到到Keyspace1下面,所以不能直接写:
set Keyspace1.Standard2['studentA']['age'] = '18'
因为这样的话就相当于直接在keyspace1下面的standard2中添加一Columns,如果你Cassandra中没有keyspace1或者没有用命令指定到keyspace1下自然会报错的。
下面我将从创建keyspace到往中间插入值开始讲起:
1. 创建keyspace (twissandra)
[default@unknown] create keyspace twissandra with replication_factor=1
and placement_strategy='org.apache.cassandra.locator.SimpleStrategy';
and placement_strategy='org.apache.cassandra.locator.SimpleStrategy';
2. 创建Column Family
[default@unknown] use twissandra; //先将当前指令定位到keyspace: twissandra下
下面创建 Column Family(users)
[default@twissandra] create column family users with comparator = UTF8Type
... and column_metadata = [{column_name: password, validation_class:
... UTF8Type}];
... and column_metadata = [{column_name: password, validation_class:
... UTF8Type}];
3. 在twissandra. Users下面插入值
[default@twissandra] set users['jsmith']['password']='ch@ngem3';
4. 获取刚插入的值
[default@twissandra] get users['jsmith'];