Reputation: 2158
As Cassandra DB is providing a option to set Time-to-live(TTL) value to automatically delete the record on the basis of TTL value set with record. I have a case that user can change the date of data expiry, means user can change the data expiration date any time.
Case:
Requirement: Whenever user changes the expiration period through UI, we wanted to change TTL in database. Is there any option to update the TTL for records in Cassandra DB.
Upvotes: 16
Views: 23087
Reputation: 79
This work on Cassandra 2.0.7
You can RE-INSERT the same data changing only TTL.
INSERT INTO Table (col1, col2 ) VALUES ( '001','aaa') USING TTL 200;
INSERT INTO Table (col1, col2 ) VALUES ( '001','aaa') USING TTL 2;
Wait 2 sec and the row disappear;
I found also this by DataStax: To change the TTL of a specific column, you must re-insert the data with a new TTL. Apache Cassandra™ upserts the column with the new TTL, replacing the old value with the old TTL, if any exists.
See this link
Upvotes: 1
Reputation: 2158
I did some R&D on this issue and I have concluded following points.
Upvotes: 13
Reputation: 20021
You can perform a "fake update"
INSERT INTO ttl_example (k, v) VALUES ('somekey', 'somevalue') USING TTL 60;
UPDATE ttl_example USING TTL 200 SET v = 'somevalue' WHERE k = 'somekey';
After the execution of second statement TTL will be 200 seconds.
HTH, Carlo
Upvotes: 5