我想根据 TTL 在 Redis 中插入到期日期。如何计算保质期?
我正在尝试使用TimeCategory
类,这是示例:
def ttl = 3600;
def date = new Date()
TimeDuration duration = getSeconds(ttl)
TimeDuration expiryDate = date.plus.duration
这是计算到期日的正确方法吗?
如果你问我,那就太复杂了。
在这里单行就足够了:
Date expiryDate = new Date( System.currentTimeMillis() + ttlInSeconds * 1000l )
确保您在long
此处使用数字,否则将减少数字,2147483647
这可能会导致大 TTL 的错误结果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句