Time To Live (TTL)

TTL is a feature that allows us to define for how long data is valid. This is defined per table or column, in seconds. It’s important to keep the node’s clock synchronized to maintain precision. 

To define it (make sure you are in the same active cqlsh prompt you created before):

CREATE TABLE heartrate_ttl (
    pet_chip_id  uuid,
    time timestamp,
    heart_rate int,
    PRIMARY KEY (pet_chip_id, time))
    WITH default_time_to_live = 604800;

To change the TTL:

ALTER TABLE heartrate_ttl WITH default_time_to_live = 3600;

Insert some data:

INSERT INTO heartrate_ttl(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:01:00', 100);

And now retrieve the TTL using the TTL function:

select pet_chip_id,time, heart_rate, TTL(heart_rate), WRITETIME(heart_rate) from heartrate_ttl;

To report this post you need to login first.