How to set TTL in Java based app for DynamoDB(如何在基于 Java 的应用程序中为 DynamoDB 设置 TTL)
问题描述
您好,我需要通过 AWS Java SDK 以编程方式为 DynamoDB 中的表设置时间.是否可以?我知道最近引入了 TTL 功能 - http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
Hi I need to set time to live programmatically for a table in DynamoDB via AWS Java SDK. Is it possible? I know that TTL feature is introduced recently - http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
更新:没有特别的注释,但我们可以手动做:
UPDATE: There is no special annotaion, but we can do it manually:
@DynamoDBAttribute
private long ttl;
并在 AWS 中将其配置为 ttl - http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/time-to-live-ttl-how-to.html
and configure it as ttl in AWS - http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/time-to-live-ttl-how-to.html
long now = Instant.now().getEpochSecond(); // unix time
long ttl = 60 * 60 * 24; // 24 hours in sec
setTtl(ttl + now); // when object will be expired
推荐答案
AmazonDynamoDBClient.updateTimeToLive
记录在 这里 或直接链接 这里
AmazonDynamoDBClient.updateTimeToLive
documented here or direct link here
这篇关于如何在基于 Java 的应用程序中为 DynamoDB 设置 TTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在基于 Java 的应用程序中为 DynamoDB 设置 TTL


- C++ 和 Java 进程之间的共享内存 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01