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
ModifierConstructorDescriptionprotected
Expiration
(long expirationTime, TimeUnit timeUnit) Creates newExpiration
. -
Method Summary
Modifier and TypeMethodDescriptionstatic Expiration
Creates newExpiration
with the providedTimeUnit
.static Expiration
Creates newExpiration
with the providedDuration
.long
getConverted
(TimeUnit targetTimeUnit) Get the expiration time converted into the desiredtargetTimeUnit
.long
Get the expiration time.long
Get the expiration time converted intoTimeUnit.MILLISECONDS
.long
Get the expiration time converted intoTimeUnit.SECONDS
.Get the time unit for the expiration time.boolean
boolean
boolean
static Expiration
keepTtl()
Obtain anExpiration
that indicates to keep the existing one.static Expiration
milliseconds
(long expirationTime) Creates newExpiration
withTimeUnit.MILLISECONDS
.static Expiration
Creates new persistentExpiration
.static Expiration
seconds
(long expirationTime) Creates newExpiration
withTimeUnit.SECONDS
.static Expiration
unixTimestamp
(long unixTimestamp, TimeUnit timeUnit) Creates newExpiration
with the given unix timestamp andTimeUnit
.
-
Constructor Details
-
Expiration
Creates newExpiration
.- Parameters:
expirationTime
- can be null. Defaulted toTimeUnit.SECONDS
timeUnit
-
-
-
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 newExpiration
withTimeUnit.SECONDS
.- Parameters:
expirationTime
-- Returns:
-
milliseconds
Creates newExpiration
withTimeUnit.MILLISECONDS
.- Parameters:
expirationTime
-- Returns:
-
unixTimestamp
Creates newExpiration
with 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 anExpiration
that indicates to keep the existing one. Eg. when sending aSET
command.NOTE: Please follow the documentation of the individual commands to see if
keepTtl()
is applicable.- Returns:
- never null.
- Since:
- 2.4
-
from
Creates newExpiration
with the providedTimeUnit
. Greater units thanTimeUnit.SECONDS
are converted toTimeUnit.SECONDS
. Units smaller thanTimeUnit.MILLISECONDS
are converted toTimeUnit.MILLISECONDS
and can lose precision sinceTimeUnit.MILLISECONDS
is the smallest granularity supported by Redis.- Parameters:
expirationTime
-timeUnit
- can be null. Defaulted toTimeUnit.SECONDS
- Returns:
-
from
Creates newExpiration
with the providedDuration
. Durations with at leastTimeUnit.SECONDS
resolution use seconds, durations using milliseconds useTimeUnit.MILLISECONDS
resolution.- Parameters:
duration
- must not be null.- Returns:
- Since:
- 2.0
-
persistent
Creates new persistentExpiration
.- Returns:
-
isPersistent
public boolean isPersistent()- Returns:
- true if
Expiration
is set to persistent.
-
isKeepTtl
public boolean isKeepTtl()- Returns:
- true if
Expiration
of existing key should not be modified. - Since:
- 2.4
-
isUnixTimestamp
public boolean isUnixTimestamp()- Returns:
- true if
Expiration
is set to a specified Unix time at which the key will expire. - Since:
- 2.6
-