您好,我正在使用Cassandra保存用户数据。我只想将用户数据存储24小时,所以我要给ttl提供24小时。对于每个用户,都有多个条目。所以我想为每个用户批量插入数据,而不是多次调用数据库。我正在使用Cassandra操作来给ttl。我可以给ttl单记录。批量插入数据时如何提供ttl
docker ps -a
如您所见,我必须遍历清单make并为每个记录进行数据库调用。批处理操作cassandraOperations.batchOps()。insert()仅接受对象列表。使用batchops()功能时如何为每个记录设置ttl?
答案 0 :(得分:0)
/**
* Add a collection of inserts with given {@link WriteOptions} to the batch.
*
* @param entities the entities to insert; must not be {@literal null}.
* @param options the WriteOptions to apply; must not be {@literal null}.
* @return {@code this} {@link CassandraBatchOperations}.
* @throws IllegalStateException if the batch was already executed.
* @since 2.0
*/
CassandraBatchOperations insert(Iterable<?> entities, WriteOptions options);
您可以使用insert(Iterable<?> entities, WriteOptions options)
方法
@EqualsAndHashCode(callSuper = true)
public class WriteOptions extends QueryOptions {
private static final WriteOptions EMPTY = new WriteOptionsBuilder().build();
private final Duration ttl;
private final @Nullable Long timestamp;
batchOperations.insert(entity, WriteOptions.builder().ttl(20).build());