📜  Cassandra中的读写路径

📅  最后修改于: 2021-08-29 10:54:22             🧑  作者: Mango

先决条件–

  • Apache Cassandra简介
  • Apache Cassandra(NOSQL数据库)
  • 卡桑德拉的体系结构

在Cassandra中写入路径执行:

  • 在Cassandra中,在写入数据时,写入操作将写入集群中的任何节点(协调器)。
  • 当任何用户插入数据时,这意味着他们首先写入数据以提交日志,然后再写入存储器。
  • 当任何用户写入数据时,每次写入都将包含一个时间戳。
  • 一旦memtable开始变满,便会定期将其刷新到磁盘(SSTable)。
  • 之后,在内存中创建一个新的内存表。
  • 在执行写路径时,删除是特殊的写案例,称为逻辑删除。

插入数据:
如果在Cassandra中插入数据,我们将创建一个键空间,然后创建一个表,然后将数据插入到表中。

例子 –

// Creating a keyspace
create keyspace UniersityData
replication = {'class': 'SimpleStrategy', 'replication_factor' : '3' };

// Creating a table and declaring the columns
create table CSE_Student(
student_id int,
name text,
email text,
primary key(student_id)
);

// Using the newly created keyspace
use UniersityData;

// Inserting values in the table for all the columns
Insert into CSE_student(student_id, name, email) 
values(012345, 'Ashish', 'ashish@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012346, 'Abi', 'abi@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012347, 'Rana', 'rana@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012348, 'Aayush', 'aayush@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012349, 'harsh', 'haarsh@gmail.com'); 

读取路径执行:

  • 在Cassandra中读取数据时,可以查询充当协调器的任何服务器。
  • 当我们想访问读取的数据时,我们使用请求的密钥联系节点。
  • 在数据中心的每个节点上,数据都从SStable中提取并合并。
  • 在Cassandra中,在考虑读取一致性的同时,我们可以检查–
    一致性

读取数据:
编写一个cqlsh查询以从CSE_student读取数据并提供相同的输出。

select * 
from CSE_student;

输出 :

index student_id name email
0 12345 Ashish ashish@gmail.com
1 12346 Abi abi@gmail.com
2 12347 Rana rana@gmail.com
3 12348 Aayush aayush@gmail.com
4 12349 harsh haarsh@gmail.com