如何通过在Cassandra中设置单独的生存时间(TTL)属性来使集合的每个元素到期? [英] How to expire each element of a collection by setting an individual time-to-live (TTL) property in Cassandra?

查看:58
本文介绍了如何通过在Cassandra中设置单独的生存时间(TTL)属性来使集合的每个元素到期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过在Cassandra中设置单独的生存时间(TTL)属性来使集合的每个元素到期?

How to expire each element of a collection by setting an individual time-to-live (TTL) property in Cassandra?

文档在这里,但我找不到示例.( https://docs.datastax.com/en/cql/3.3/cql/cql_using/useExpire.html )

the documentation is here, but I cannot find an example. (https://docs.datastax.com/en/cql/3.3/cql/cql_using/useExpire.html)

推荐答案


如果要在cassandra的同一列集合(集合,列表,地图)中使用不同的TTL.

在此示例中喜欢:

有一个表-> tableName
文本类型的一列(col1)主键
类型为set< long>


If you want to have different TTL in a same column collection (set, list, map) of cassandra.

Do like in this example:

There is a table -> tableName
whih one column (col1) primary key of text type
A column(col2) of type set <long>

UPDATE tableName USING TTL 30 SET col2=col2+{11} WHERE col1=-10;
UPDATE tableName USING TTL 88 SET col2=col2+{22} WHERE col1=-10;

在该示例中,我将设置值设置为TTL = 30的{11}和TTL = 88的{22}.当一个元素超过TTL时,它将被自动删除.
当集合中的所有元素都超过TTL并且集合为空时,该行也会被删除.

In the example I am upserting to values to the set, {11} with TTL=30 and {22} with TTL=88.
When one element exeeds the TTL it is automaticaly deleted.
When all the elements in the set exceeds the TTL and the set is empty, the row is also deleted.

这篇关于如何通过在Cassandra中设置单独的生存时间(TTL)属性来使集合的每个元素到期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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