Class Expiration
java.lang.Object
org.springframework.data.redis.core.types.Expiration
-
Constructor Summary
ModifierConstructorDescriptionprotected
Expiration
(long expirationTime, TimeUnit timeUnit) Creates newExpiration
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
static Expiration
Creates newExpiration
with the providedTimeUnit
.static Expiration
Creates a newExpiration
with the given, requiredDuration
.long
getConverted
(TimeUnit targetTimeUnit) Convertsexpiration time
into the given, desiredTimeUnit
.long
Get thelength of time
for thisExpiration
.long
Get theexpiration time
converted intoTimeUnit.MILLISECONDS
.long
Get theexpiration time
converted intoTimeUnit.SECONDS
.Get the configuredTimeUnit
for theexpiration time
.int
hashCode()
boolean
boolean
boolean
static Expiration
keepTtl()
Obtain anExpiration
that indicates to keep the existing one, e.g. when sending aSET
command.static Expiration
milliseconds
(long expirationTime) Creates a newExpiration
inTimeUnit.MILLISECONDS
.static Expiration
Creates a new persistent, non-expiringExpiration
.static Expiration
seconds
(long expirationTime) Creates a newExpiration
inTimeUnit.SECONDS
.static Expiration
unixTimestamp
(long unixTimestamp, TimeUnit timeUnit) Creates a newExpiration
with the given unix timestamp andTimeUnit
.
-
Constructor Details
-
Expiration
Creates newExpiration
.- Parameters:
expirationTime
-length of time
for expiration. Defaulted toTimeUnit.SECONDS
.timeUnit
-TimeUnit
used to measureexpirationTime
.
-
-
Method Details
-
milliseconds
Creates a newExpiration
inTimeUnit.MILLISECONDS
.- Parameters:
expirationTime
-length of time
for expiration.- Returns:
- a new
Expiration
measured inTimeUnit.MILLISECONDS
.
-
seconds
Creates a newExpiration
inTimeUnit.SECONDS
.- Parameters:
expirationTime
-length of time
for expiration.- Returns:
- a new
Expiration
measured inTimeUnit.SECONDS
.
-
unixTimestamp
Creates a newExpiration
with the given unix timestamp andTimeUnit
.- Parameters:
unixTimestamp
-unix timestamp
at which the key will expire.timeUnit
-TimeUnit
used to measure the expiration period; must not be null.- Returns:
- a new
Expiration
with the given unix timestamp andTimeUnit
.
-
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
-length of time
for theExpiration
.timeUnit
-TimeUnit
used to measure theexpiration time
; can be null. Defaulted toTimeUnit.SECONDS
- Returns:
- a new
Expiration
configured with the givenlength of time
inTimeUnit
.
-
from
Creates a newExpiration
with the given, requiredDuration
.Durations with at least seconds resolution uses
TimeUnit.SECONDS
.Durations
in milliseconds useTimeUnit.MILLISECONDS
.- Parameters:
duration
- must not be null.- Returns:
- a new
Expiration
from the givenDuration
. - Since:
- 2.0
-
keepTtl
Obtain anExpiration
that indicates to keep the existing one, e.g. when sending aSET
command.NOTE: Please follow the documentation for the individual commands to see if keeping the existing TTL is applicable.
- Returns:
- never null.
- Since:
- 2.4
-
persistent
Creates a new persistent, non-expiringExpiration
.- Returns:
- a new persistent, non-expiring
Expiration
.
-
getExpirationTime
public long getExpirationTime()Get thelength of time
for thisExpiration
.- Returns:
- the
length of time
for thisExpiration
.
-
getExpirationTimeInMilliseconds
public long getExpirationTimeInMilliseconds()Get theexpiration time
converted intoTimeUnit.MILLISECONDS
.- Returns:
- the expiration time converted into
TimeUnit.MILLISECONDS
.
-
getExpirationTimeInSeconds
public long getExpirationTimeInSeconds()Get theexpiration time
converted intoTimeUnit.SECONDS
.- Returns:
- the
expiration time
converted intoTimeUnit.SECONDS
.
-
getTimeUnit
Get the configuredTimeUnit
for theexpiration time
.- Returns:
- the configured
TimeUnit
for theexpiration time
.
-
getConverted
Convertsexpiration time
into the given, desiredTimeUnit
.- Parameters:
targetTimeUnit
-TimeUnit
used to convert thegetExpirationTime()
expiration time}; must not be null.- Returns:
- the
expiration time
converted into the given, desiredTimeUnit
. - Throws:
IllegalArgumentException
- if the givenTimeUnit
is null.
-
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
-
equals
-
hashCode
public int hashCode()
-