更新列值并为整行设置生存时间(TTL)的方法是什么?

huangapple go评论67阅读模式
英文:

How do I update a column value and set a TTL for the whole row?

问题

I'm trying to update a column value (not key column) and to set a new TTL for the whole row. But when I execute the generated statement, only the column TTL was updated, and the other columns remain with the original values, producing NULL values in future reads.

My app was written in Java and uses DataStax for querying. The function for generating the statement is something like this:

private Statement updateLastActivityStatement(int ttl, Long ts){
    return QueryBuilder.update(KEY_SPACE, TABLE_NAME)
        .with(QueryBuilder.set(LAST_ACTIVITY, ts))
        .where(QueryBuilder.eq(ENTRY_ID, userA))
        .and(QueryBuilder.eq(ID, userB))
        .using(QueryBuilder.ttl(ttl));
}
英文:

i'm trying to update a column value (not key column) and to set new TTL for the whole row.
But when i execute the generated statement, only column ttl was updates and the other columns remain with the original, producing NULL values in future reads.

My app was written in Java and using datastax for querying, and the function for generating the statement is something like this.

private Statement updateLastActivityStatement(int ttl, Long ts){
    return QueryBuilder.update(KEY_SPACE, TABLE_NAME)
        .with(QueryBuilder.set(LAST_ACTIVITY, ts))
        .where(QueryBuilder.eq(ENTRY_ID, userA))
        .and(QueryBuilder.eq(ID, userB))
        .using(QueryBuilder.ttl(ttl));
}

答案1

得分: 1

TTL与特定单元绑定,因此当您仅更新特定列时,只有这些列会被更新。要更新所有内容,您需要更新所有值。

英文:

TTL is bound to a specific cell, so when you're updating only specific columns, then only them are updated. To update everything, you need to update all values

答案2

得分: 1

TTL 仅适用于语句中的列,不适用于行中的所有列,也不适用于分区中的所有行。

我能想到的唯一解决方法是使用 default_time_to_live 选项在表上设置默认 TTL。祝好运!

英文:

The TTL only applies to the columns in the statement, not to all the columns in the row nor all the rows in the partition.

The only workaround I could think of is to set a default TTL on the table using the default_time_to_live option. Cheers!

huangapple
  • 本文由 发表于 2023年5月18日 02:44:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76275293.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定