Expiring columns with TTL

We first encountered the CQL DELETE command, which allows us to remove the value of a column or an entire row, in Chapter 5, Establishing Relationships. Another way to remove data from Cassandra is to give it a time-to-live (TTL). This is equivalent to deleting data in the future: when we write data with a TTL, it is marked as deleted after the amount of time we specify has elapsed.

CQL allows us to attach a TTL to any INSERT or UPDATE statement. Let's experiment with setting an expiring location value:

UPDATE "users" USING TTL 30 SET "location" = 'Vancouver' WHERE "username" = 'bob'; 

TTL values are given in seconds, so what we've done here is tell Cassandra that bob's location should be Vancouver for the next ...

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.