java.lang.Object
org.springframework.data.redis.connection.convert.Converters
Direct Known Subclasses:
LettuceConverters

public abstract class Converters extends Object
Common type converters.
Author:
Jennifer Hickey, Thomas Darimont, Mark Paluch, Christoph Strobl, daihuabin, John Blum, Sorokin Evgeniy, Marcin Grzejszczak
  • Constructor Details

    • Converters

      public Converters()
  • Method Details

    • identityConverter

      public static <T> Converter<T,T> identityConverter()
      Returns a Converter that always returns its input argument.
      Type Parameters:
      T - the type of the input and output objects to the function
      Returns:
      a function that always returns its input argument
      Since:
      2.5
    • stringToBoolean

      public static Boolean stringToBoolean(String source)
    • stringToBooleanConverter

      public static Converter<String,Boolean> stringToBooleanConverter()
    • stringToProps

      public static Converter<String,Properties> stringToProps()
    • longToBoolean

      public static Converter<Long,Boolean> longToBoolean()
    • stringToDataType

      public static Converter<String,DataType> stringToDataType()
    • toProperties

      public static Properties toProperties(String source)
    • toProperties

      public static Properties toProperties(Map<?,?> source)
    • toBoolean

      public static Boolean toBoolean(@Nullable Long source)
    • toDataType

      public static DataType toDataType(String source)
    • toBit

      public static byte[] toBit(Boolean source)
    • toClusterNode

      protected static RedisClusterNode toClusterNode(String clusterNodesLine)
      Converts the result of a single line of CLUSTER NODES into a RedisClusterNode.
      Parameters:
      clusterNodesLine -
      Returns:
      Since:
      1.7
    • toSetOfRedisClusterNodes

      public static Set<RedisClusterNode> toSetOfRedisClusterNodes(Collection<String> lines)
      Converts lines from the result of CLUSTER NODES into RedisClusterNodes.
      Parameters:
      lines -
      Returns:
      Since:
      1.7
    • toSetOfRedisClusterNodes

      public static Set<RedisClusterNode> toSetOfRedisClusterNodes(String clusterNodes)
      Converts the result of CLUSTER NODES into RedisClusterNodes.
      Parameters:
      clusterNodes -
      Returns:
      Since:
      1.7
    • toObjects

      public static List<Object> toObjects(Set<Tuple> tuples)
    • toTimeMillis

      public static Long toTimeMillis(String seconds, String microseconds)
      Returns the timestamp constructed from the given seconds and microseconds.
      Parameters:
      seconds - server time in seconds
      microseconds - elapsed microseconds in current second
      Returns:
    • toTimeMillis

      public static Long toTimeMillis(String seconds, String microseconds, TimeUnit unit)
      Returns the timestamp constructed from the given seconds and microseconds.
      Parameters:
      seconds - server time in seconds.
      microseconds - elapsed microseconds in current second.
      unit - target unit.
      Returns:
      Since:
      2.5
    • secondsToTimeUnit

      public static long secondsToTimeUnit(long seconds, TimeUnit targetUnit)
      Converts seconds to the given TimeUnit.
      Parameters:
      seconds -
      targetUnit - must not be null.
      Returns:
      Since:
      1.8
    • secondsToTimeUnit

      public static Converter<Long,Long> secondsToTimeUnit(TimeUnit timeUnit)
      Creates a new Converter to convert from seconds to the given TimeUnit.
      Parameters:
      timeUnit - muist not be null.
      Returns:
      Since:
      1.8
    • millisecondsToTimeUnit

      public static long millisecondsToTimeUnit(long milliseconds, TimeUnit targetUnit)
      Converts milliseconds to the given TimeUnit.
      Parameters:
      milliseconds -
      targetUnit - must not be null.
      Returns:
      Since:
      1.8
    • millisecondsToTimeUnit

      public static Converter<Long,Long> millisecondsToTimeUnit(TimeUnit timeUnit)
      Creates a new Converter to convert from milliseconds to the given TimeUnit.
      Parameters:
      timeUnit - must not be null.
      Returns:
      Since:
      1.8
    • deserializingGeoResultsConverter

      public static <V> Converter<GeoResults<RedisGeoCommands.GeoLocation<byte[]>>,GeoResults<RedisGeoCommands.GeoLocation<V>>> deserializingGeoResultsConverter(RedisSerializer<V> serializer)
      Converter capable of deserializing GeoResults.
      Parameters:
      serializer -
      Returns:
      Since:
      1.8
    • distanceConverterForMetric

      public static Converter<Double,Distance> distanceConverterForMetric(Metric metric)
      Converter capable of converting Double into Distance using given Metric.
      Parameters:
      metric -
      Returns:
      Since:
      1.8
    • toProperties

      public static Properties toProperties(List<String> input)
      Converts array outputs with key-value sequences (such as produced by CONFIG GET) from a List to Properties.
      Parameters:
      input - must not be null.
      Returns:
      the mapped result.
      Since:
      2.0
    • listToPropertiesConverter

      public static Converter<List<String>,Properties> listToPropertiesConverter()
      Returns a converter to convert array outputs with key-value sequences (such as produced by CONFIG GET) from a List to Properties.
      Returns:
      the converter.
      Since:
      2.0
    • mapToPropertiesConverter

      public static <K, V> Converter<Map<K,V>,Properties> mapToPropertiesConverter()
      Returns a converter to convert from Map to Properties.
      Returns:
      the converter.
      Since:
      2.0
    • secondsToDuration

      @Nullable public static Duration secondsToDuration(@Nullable Long seconds)
      Convert the given nullable seconds to a Duration or null.
      Parameters:
      seconds - can be null.
      Returns:
      given seconds as Duration or null.
      Since:
      2.1
    • parse

      public static <T> T parse(Object source, Class<T> targetType)
      Parse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion of byte[] and ByteBuffer.
      Type Parameters:
      T -
      Parameters:
      source - the source to parse
      targetType - eg. Map, String,...
      Returns:
      Since:
      2.3
    • parse

      public static Object parse(Object source, String sourcePath, Map<String,Class<?>> typeHintMap)
      Parse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion of byte[] and ByteBuffer based on the sourcePath and a typeHintMap
      Parameters:
      source - the source to parse
      sourcePath - the current path (use "root", for level 0).
      typeHintMap - source path to target type hints allowing wildcards (*).
      Returns:
      Since:
      2.3
    • entryOf

      public static <K, V> Map.Entry<K,V> entryOf(@Nullable K key, @Nullable V value)
      Create an Map.Entry from key and value.
      Type Parameters:
      K -
      V -
      Parameters:
      key -
      value -
      Returns:
      Since:
      2.6