spring-projects / spring-data-cassandra

Provides support to increase developer productivity in Java when using Apache Cassandra. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-cassandra/
Apache License 2.0
374 stars 310 forks source link

How can set the Ttl when update? #1378

Closed Tingfing6 closed 1 year ago

Tingfing6 commented 1 year ago

boolean res = cassandraTemplate.update(getPrimaryIdAndUserIdQuery(toUserId), update, UserRecentCupidCd.class); How can I set the expiration time of this data while updating ?I am using spring-data-cassandra:3.0.2.RELEASE and I cannot find how to set the expiration time of this data

mp911de commented 1 year ago

You can provide the TTL via UpdateOptions on your Query:

Query q = …;
q = q.queryOptions(UpdateOptions.builder().ttl(Duration.ofSeconds(10)).build());
cassandraTemplate.update(q, update, UserRecentCupidCd.class);