Class Expiration

java.lang.Object
org.springframework.data.redis.core.types.Expiration

public class Expiration extends Object
Expiration holds a value with its associated TimeUnit.
Since:
1.7
Author:
Christoph Strobl, Mark Paluch
  • Constructor Details

  • Method Details

    • getExpirationTimeInMilliseconds

      public long getExpirationTimeInMilliseconds()
      Get the expiration time converted into TimeUnit.MILLISECONDS.
      Returns:
    • getExpirationTimeInSeconds

      public long getExpirationTimeInSeconds()
      Get the expiration time converted into TimeUnit.SECONDS.
      Returns:
    • getExpirationTime

      public long getExpirationTime()
      Get the expiration time.
      Returns:
    • getTimeUnit

      public TimeUnit getTimeUnit()
      Get the time unit for the expiration time.
      Returns:
    • getConverted

      public long getConverted(TimeUnit targetTimeUnit)
      Get the expiration time converted into the desired targetTimeUnit.
      Parameters:
      targetTimeUnit - must not null.
      Returns:
      Throws:
      IllegalArgumentException
    • seconds

      public static Expiration seconds(long expirationTime)
      Creates new Expiration with TimeUnit.SECONDS.
      Parameters:
      expirationTime -
      Returns:
    • milliseconds

      public static Expiration milliseconds(long expirationTime)
      Parameters:
      expirationTime -
      Returns:
    • unixTimestamp

      public static Expiration unixTimestamp(long unixTimestamp, TimeUnit timeUnit)
      Creates new Expiration with the given unix timestamp and TimeUnit.
      Parameters:
      unixTimestamp - the unix timestamp at which the key will expire.
      timeUnit - must not be null.
      Returns:
      new instance of Expiration.
    • keepTtl

      public static Expiration keepTtl()
      Obtain an Expiration that indicates to keep the existing one. Eg. when sending a SET command.

      NOTE: Please follow the documentation of the individual commands to see if keepTtl() is applicable.

      Returns:
      never null.
      Since:
      2.4
    • from

      public static Expiration from(long expirationTime, @Nullable TimeUnit timeUnit)
      Creates new Expiration with the provided TimeUnit. Greater units than TimeUnit.SECONDS are converted to TimeUnit.SECONDS. Units smaller than TimeUnit.MILLISECONDS are converted to TimeUnit.MILLISECONDS and can lose precision since TimeUnit.MILLISECONDS is the smallest granularity supported by Redis.
      Parameters:
      expirationTime -
      timeUnit - can be null. Defaulted to TimeUnit.SECONDS
      Returns:
    • from

      public static Expiration from(Duration duration)
      Creates new Expiration with the provided Duration. Durations with at least TimeUnit.SECONDS resolution use seconds, durations using milliseconds use TimeUnit.MILLISECONDS resolution.
      Parameters:
      duration - must not be null.
      Returns:
      Since:
      2.0
    • persistent

      public static Expiration persistent()
      Creates new persistent Expiration.
      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