Check a rows TTL in cassandra?
Asked Answered
C

1

26

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;
Cacophonous answered 28/9, 2013 at 12:58 Comment(1)
docs.datastax.com/en/cql/3.0/cql/cql_using/use_ttl_t.htmlTrinitroglycerin
S
55

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.

Solidify answered 28/9, 2013 at 13:5 Comment(3)
Excellent detailed but concise answer. Thanks!Cacophonous
this is not working for me : somebody else had the same issue #22201500Shroff
Works for me. Perhaps post a question detailing your exact scenario.Cacophonous

© 2022 - 2024 — McMap. All rights reserved.