gpt4 book ai didi

cassandra - Cassandra 中的更新不是反模式吗?

转载 作者:行者123 更新时间:2023-12-05 00:50:47 25 4
gpt4 key购买 nike

根据 Datastax 文档,在 Cassandra 中先读后写是一种反模式。

每当我们在 CQLSH 中使用 UPDATE 或使用 Datastax 驱动程序来设置几列(带有 IF 和集合更新)时,它是否不会先读取再写入?这不是反模式吗?我错过了什么吗?

P.S 我不是在谈论纯粹的 UPSERTS,而是在特定列上的更新。

蒂亚!

最佳答案

不,更新不是反模式。

在 Cassandra 中,更新是一种类似于插入的 upsert 操作。

UPDATE writes one or more column values to a row in a Cassandra table. Like INSERT, UPDATE is an upsert operation: if the specified row does not exist, the command creates it. All UPDATEs within the same partition key are applied atomically and in isolation.



但是 Lightweight transactions在写操作之前被读取。实际上以四次往返为代价。

轻量级交易示例:
#Lightweight transaction Insert
INSERT INTO customer_account (customerID, customer_email)
VALUES (‘LauraS’, ‘lauras@gmail.com’)
IF NOT EXISTS;

#Lightweight transaction Update
UPDATE customer_account
SET customer_email=’laurass@gmail.com’
IF customerID=’LauraS’;

以上两种说法都是轻量级交易

来源: http://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlUpdate.html#cqlUpdate__description

关于cassandra - Cassandra 中的更新不是反模式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45491451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com