Class Expiration
java.lang.Object
org.springframework.data.redis.core.types.Expiration
Expiration holds a value with its associated
TimeUnit.- Since:
- 1.7
- Author:
- Christoph Strobl, Mark Paluch
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedExpiration(long expirationTime, TimeUnit timeUnit) Creates newExpiration. -
Method Summary
Modifier and TypeMethodDescriptionstatic ExpirationCreates newExpirationwith the providedTimeUnit.static ExpirationCreates newExpirationwith the providedDuration.longgetConverted(TimeUnit targetTimeUnit) Get the expiration time converted into the desiredtargetTimeUnit.longGet the expiration time.longGet the expiration time converted intoTimeUnit.MILLISECONDS.longGet the expiration time converted intoTimeUnit.SECONDS.Get the time unit for the expiration time.booleanbooleanbooleanstatic ExpirationkeepTtl()Obtain anExpirationthat indicates to keep the existing one.static Expirationmilliseconds(long expirationTime) Creates newExpirationwithTimeUnit.MILLISECONDS.static ExpirationCreates new persistentExpiration.static Expirationseconds(long expirationTime) Creates newExpirationwithTimeUnit.SECONDS.static ExpirationunixTimestamp(long unixTimestamp, TimeUnit timeUnit) Creates newExpirationwith the given unix timestamp andTimeUnit.
-
Constructor Details
-
Expiration
Creates newExpiration.- Parameters:
expirationTime- can be null. Defaulted toTimeUnit.SECONDStimeUnit-
-
-
Method Details
-
getExpirationTimeInMilliseconds
public long getExpirationTimeInMilliseconds()Get the expiration time converted intoTimeUnit.MILLISECONDS.- Returns:
-
getExpirationTimeInSeconds
public long getExpirationTimeInSeconds()Get the expiration time converted intoTimeUnit.SECONDS.- Returns:
-
getExpirationTime
public long getExpirationTime()Get the expiration time.- Returns:
-
getTimeUnit
Get the time unit for the expiration time.- Returns:
-
getConverted
Get the expiration time converted into the desiredtargetTimeUnit.- Parameters:
targetTimeUnit- must not null.- Returns:
- Throws:
IllegalArgumentException
-
seconds
Creates newExpirationwithTimeUnit.SECONDS.- Parameters:
expirationTime-- Returns:
-
milliseconds
Creates newExpirationwithTimeUnit.MILLISECONDS.- Parameters:
expirationTime-- Returns:
-
unixTimestamp
Creates newExpirationwith the given unix timestamp andTimeUnit.- Parameters:
unixTimestamp- the unix timestamp at which the key will expire.timeUnit- must not be null.- Returns:
- new instance of
Expiration.
-
keepTtl
Obtain anExpirationthat indicates to keep the existing one. Eg. when sending aSETcommand.NOTE: Please follow the documentation of the individual commands to see if
keepTtl()is applicable.- Returns:
- never null.
- Since:
- 2.4
-
from
Creates newExpirationwith the providedTimeUnit. Greater units thanTimeUnit.SECONDSare converted toTimeUnit.SECONDS. Units smaller thanTimeUnit.MILLISECONDSare converted toTimeUnit.MILLISECONDSand can lose precision sinceTimeUnit.MILLISECONDSis the smallest granularity supported by Redis.- Parameters:
expirationTime-timeUnit- can be null. Defaulted toTimeUnit.SECONDS- Returns:
-
from
Creates newExpirationwith the providedDuration. Durations with at leastTimeUnit.SECONDSresolution use seconds, durations using milliseconds useTimeUnit.MILLISECONDSresolution.- Parameters:
duration- must not be null.- Returns:
- Since:
- 2.0
-
persistent
Creates new persistentExpiration.- Returns:
-
isPersistent
public boolean isPersistent()- Returns:
- true if
Expirationis set to persistent.
-
isKeepTtl
public boolean isKeepTtl()- Returns:
- true if
Expirationof existing key should not be modified. - Since:
- 2.4
-
isUnixTimestamp
public boolean isUnixTimestamp()- Returns:
- true if
Expirationis set to a specified Unix time at which the key will expire. - Since:
- 2.6
-