cassandra基础操作
程序员文章站
2024-03-19 22:27:46
...
cassandra查询操作: 登陆: ./cassandra-cli connect localhost/9160;
创建表: create keyspace ShoppingCart with placement_strategy = 'SimpleStrategy' and strategy_options = {replication_factor:2} and durable_writes = true;
use ShoppingCart;
create column family i with column_type = 'Standard' and comparator = 'UTF8Type' and default_validation_class = 'BytesType' and key_validation_class = 'UTF8Type' and read_repair_chance = 0.1 and gc_grace = 86400 and min_compaction_threshold = 4 and max_compaction_threshold = 32 and replicate_on_write = true and compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy';
插入数据: set i['1bdae1ac0a7a3ea3a702dd7b24d2f0f82ae4397402026b879b893e5d5df3fee9|USA']['V'] = utf8('fff');
查看i表所有数据: list i;
根据rowkey查询数据 格式:get i['rowkey']: get i['1bdae1ac0a7a3ea3a702dd7b24d2f0f82ae4397402026b879b893e5d5df3fee9|USA'];
根据rowkey查询数据后查询指定字段 格式 get i['rowkey'][column] get i['1bdae1ac0a7a3ea3a702dd7b24d2f0f82ae4397402026b879b893e5d5df3fee9|USA'][V];
删除一列可以使用del命令: del i['1bdae1ac0a7a3ea3a702dd7b24d2f0f82ae4397402026b879b893e5d5df3fee9|USA']['V'];
想要删除一行数据: del i['1bdae1ac0a7a3ea3a702dd7b24d2f0f82ae4397402026b879b893e5d5df3fee9|USA'];
删除所有数据 truncate table i;
登录cql ./cql ip
CREATE KEYSPACE ecommerce WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true; CREATE TABLE ecommerce."ShoppingCart" ( key text, column1 text, value text, PRIMARY KEY (key, column1) ) WITH COMPACT STORAGE AND CLUSTERING ORDER BY (column1 ASC) AND bloom_filter_fp_chance = 0.01 AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} AND comment = '' AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'} AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'} AND crc_check_chance = 1.0 AND dclocal_read_repair_chance = 0.1 AND default_time_to_live = 10 AND gc_grace_seconds = 86400 AND max_index_interval = 2048 AND memtable_flush_period_in_ms = 0 AND min_index_interval = 128 AND read_repair_chance = 0.1 AND speculative_retry = 'NONE';
CREATE TABLE ecommerce.ShoppingCart( id int,s_name varchar, PRIMARY KEY(id)) WITH COMPACT STORAGE AND default_time_to_live = 10 ;
INSERT INTO ecommerce.ShoppingCart (id,s_name) VALUES (1,'Naruto');
上一篇: 第五节 Spring MVC