I want to insert expiration date in Redis based on TTL. How can I count the expiration date?
I'm trying to use TimeCategory
class, here is the example:
def ttl = 3600;
def date = new Date()
TimeDuration duration = getSeconds(ttl)
TimeDuration expiryDate = date.plus.duration
Is that a correct approach to expiry date counting?
Overcomplicated if you ask me.
One-liner should be sufficient here:
Date expiryDate = new Date( System.currentTimeMillis() + ttlInSeconds * 1000l )
Make sure you are using long
numbers here, otherwise the numbers will be cut down to 2147483647
which might lead to wrong results for large TTLs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.