问题描述
您好,我需要通过 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!