Reputation: 143
Not able use TTL with spring data CassandraRepository based implementation.
Spring data cassandra version: Latest
I am trying to use TTL property of cassandra for save operation using spring data repository based implementation. however looking at the reference documentation(https://docs.spring.io/spring-data/cassandra/docs/current/reference/html/) i dont see any straight forward way of using it.
Even though docs mentioned that we can use it but no example provided for repository based implementation. Do note that i see some example using cqlTemplate and cassadraOperations. But none for repository.
No code written yet as I am trying to figure out how to use it
Expectation would be some kind @TTL(value in seconds) annotation on repository save/update method for easier implementation.
Upvotes: 0
Views: 2480
Reputation: 33
Refer to A Sarkar's answer from this post TTL support in spring boot application using spring-data-cassandra
Please see my sample code here, https://github.com/nontster/spring-data-cassandra-demo
I borrow sample code from this tutorial https://www.baeldung.com/spring-data-cassandra-tutorial
You need to create demo keyspace before you can run this code,
CREATE KEYSPACE demo WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1};
Run saveBookTest() method in BookRepositoryIntegrationTest.java and you can see countdown TTL in column via (I set TTL to 600 seconds)
cqlsh:demo> SELECT title,TTL(year) FROM Book WHERE title='Head First Java' AND publisher='O''Reilly Media';
title | ttl(year)
-----------------+-----------
Head First Java | 597
(1 rows)
Upvotes: 3