Check a rows TTL in cassandra?

Jay picture Jay · Sep 28, 2013 · Viewed 23.9k times · Source

I have a table/column family which I am inserting rows that expire after a certain amount of time. Is it possible to then query the table to check which rows are going to expire soon (for diagnostic purposes, ie something like this:

select subject, ?ttl? from discussions;

Answer

Richard picture Richard · Sep 28, 2013

You can do

select subject, TTL(subject) from discussions;

to return the remaining TTL in seconds for subject.

E.g.

> insert into discussions (uid, subject) VALUES (now(), 'hello') using ttl 100;
> select subject, TTL(subject) from discussions;

 subject | ttl(subject)
---------+--------------
   hello |           84

since I waited 16 seconds before running the select.