问题
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