Class TimeoutUtils

java.lang.Object
org.springframework.data.redis.core.TimeoutUtils

public abstract class TimeoutUtils extends Object
Helper class featuring methods for calculating Redis timeouts
Author:
Jennifer Hickey, Mark Paluch, Christoph Strobl
  • Constructor Details

    • TimeoutUtils

      public TimeoutUtils()
  • Method Details

    • hasMillis

      public static boolean hasMillis(Duration duration)
      Check if a given Duration can be represented in sec or requires msec representation.
      Parameters:
      duration - the actual Duration to inspect. Never null.
      Returns:
      true if the Duration contains millisecond information.
      Since:
      2.1
    • toSeconds

      public static long toSeconds(Duration duration)
      Converts the given timeout to seconds.

      Since a 0 timeout blocks some Redis ops indefinitely, this method will return 1 if the original value is greater than 0 but is truncated to 0 on conversion.

      Parameters:
      duration - The duration to convert
      Returns:
      The converted timeout
      Since:
      2.3
    • toSeconds

      public static long toSeconds(long timeout, TimeUnit unit)
      Converts the given timeout to seconds.

      Since a 0 timeout blocks some Redis ops indefinitely, this method will return 1 if the original value is greater than 0 but is truncated to 0 on conversion.

      Parameters:
      timeout - The timeout to convert
      unit - The timeout's unit
      Returns:
      The converted timeout
    • toDoubleSeconds

      public static double toDoubleSeconds(long timeout, TimeUnit unit)
      Converts the given timeout to seconds with a fraction of seconds.
      Parameters:
      timeout - The timeout to convert
      unit - The timeout's unit
      Returns:
      The converted timeout
      Since:
      2.6
    • toMillis

      public static long toMillis(long timeout, TimeUnit unit)
      Converts the given timeout to milliseconds.

      Since a 0 timeout blocks some Redis ops indefinitely, this method will return 1 if the original value is greater than 0 but is truncated to 0 on conversion.

      Parameters:
      timeout - The timeout to convert
      unit - The timeout's unit
      Returns:
      The converted timeout