只需在一行上设置 TTL [英] Just set the TTL on a row

查看:26
本文介绍了只需在一行上设置 TTL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Java,我可以扫描 Cassandra 表并只更新一行的 TTL 吗?我不想更改任何数据.我只想扫描 Cassandra 表并设置几行的 TTL.

Using Java, can I scan a Cassandra table and just update the TTL of a row? I don't want to change any data. I just want to scan Cassandra table and set TTL of a few rows.

另外,使用java,我可以设置绝对的TTL.例如 (2016-11-22 00:00:00).所以我不想以秒为单位指定TTL,而是以时间指定绝对值.

Also, using java, can I set TTL which is absolute. for example (2016-11-22 00:00:00). so I don't want to specify the TTL in seconds, but specify the absolute value in time.

推荐答案

Cassandra 不允许为 设置 TTL 值,它允许为列设置 TTL 仅.

Cassandra doesn't allow to set the TTL value for a row, it allows to set TTLs for columns values only.

如果您想知道为什么您遇到到期,这是因为如果所有记录的所有列的值都是 TTLed,然后当您尝试 SELECT 时该行消失.

In the case you're wondering why you are experiencing rows expiration, this is because if all the values of all the columns of a record are TTLed then the row disappears when you try to SELECT it.

然而,只有当您使用 USING TTL 执行 INSERT 时,这才是正确的.如果您在没有 TTL 的情况下 INSERT 然后使用 TTL 执行 UPDATE 您仍然会看到该行,但值为空.下面是一些示例和一些问题:

However, this is only true if you perform an INSERT with the USING TTL. If you INSERT without TTL and then do an UPDATE with TTL you'll still see the row, but with null values. Here's a few examples and some gotchas:

CREATE TABLE test (
    k text PRIMARY KEY,
    v int,
);

INSERT INTO test (k,v) VALUES ('test', 1) USING TTL 10;

... 10 seconds after...

SELECT * FROM test ;

 k             | v
---------------+---------------

<小时>

带有 TTLed INSERT 和 TTLed UPDATE 的示例:


Example with a TTLed INSERT and a TTLed UPDATE:

INSERT INTO test (k,v) VALUES ('test', 1) USING TTL 10;
UPDATE test USING TTL 10 SET v=0 WHERE k='test';

... 10 seconds after...

SELECT * FROM test;

 k             | v
---------------+---------------

<小时>

带有非 TTLed INSERT 和 TTLed UPDATE

的示例


Example with a non-TTLed INSERT with a TTLed UPDATE

INSERT INTO test (k,v) VALUES ('test', 1);
UPDATE test USING TTL 10 SET v=0 WHERE k='test';

... 10 seconds after...

SELECT * FROM test;

 k             | v
---------------+---------------
          test |          null

现在您可以看到解决问题的唯一方法是用新的 TTL 重写所有行中所有列的值.

Now you can see that the only way to solve you problem is to rewrite all the values of all the columns of your row with a new TTL.

此外,无法指定明确的到期日期,但您可以通过简单的数学计算在内获得一个简单的 TTL 值(如其他人建议的那样).

In addition, there's no way to specify an explicit expiration date, but you can get a simple TTL value in seconds with simple math (as other suggested).

查看官方文档数据过期.并且不要忘记查看 DELETE 用于更新 TTL 的部分.

Have a look at the official documentation about data expiration. And don't forget to have a look at the DELETE section for updating TTLs.

HTH.

这篇关于只需在一行上设置 TTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆