如何在基于Java的DynamoDB应用中设置TTL [英] How to set TTL in Java based app for DynamoDB

查看:285
本文介绍了如何在基于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 此处或直接链接此处

这篇关于如何在基于Java的DynamoDB应用中设置TTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆