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

爱⌒轻易说出口 提交于 2019-12-11 10:19:53

问题


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

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


回答1:



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;

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.



来源:https://stackoverflow.com/questions/36166382/how-to-expire-each-element-of-a-collection-by-setting-an-individual-time-to-live

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!