Vijay Nandwana
Vijay Nandwana

Reputation: 2644

How to set TTL on one record rather than on an entire row?

Is there any way in Cassandra to set TTL for only one record (one column), not for entire row. For ex, there is a table which has temporary users data and in it their is a field OTP which expires in 30 minutes. I'm trying to figure out how to set TTL only on OTP record not on entire user field row.

All the examples I found so far sets TTL on entire row not on any specific record. I'm using Spring Data for Cassandra.

Upvotes: 0

Views: 343

Answers (1)

Ashraful Islam
Ashraful Islam

Reputation: 12850

Insert the field using separate query with TTL

If your table name is users and primary key is userid then insert the OTP field with userid using TTL 30 * 60 = 1800 seconds

INSERT INTO users(userid, OTP) values(?, ?) USING TTL 1800;

Upvotes: 4

Related Questions