Class Converters
java.lang.Object
org.springframework.data.redis.connection.convert.Converters
- Direct Known Subclasses:
LettuceConverters
Common type converters
- Author:
- Jennifer Hickey, Thomas Darimont, Mark Paluch, Christoph Strobl, John Blum, Sorokin Evgeniy
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V> org.springframework.core.convert.converter.Converter<org.springframework.data.geo.GeoResults<RedisGeoCommands.GeoLocation<byte[]>>,org.springframework.data.geo.GeoResults<RedisGeoCommands.GeoLocation<V>>> deserializingGeoResultsConverter(RedisSerializer<V> serializer) Convertercapable of deserializingGeoResults.static org.springframework.core.convert.converter.Converter<Double,org.springframework.data.geo.Distance> distanceConverterForMetric(org.springframework.data.geo.Metric metric) Convertercapable of converting Double intoDistanceusing givenMetric.static <K,V> Map.Entry<K, V> entryOf(K key, V value) static <T> org.springframework.core.convert.converter.Converter<T,T> Returns aConverterthat always returns its input argument.static org.springframework.core.convert.converter.Converter<List<String>,Properties> Returns a converter to convert array outputs with key-value sequences (such as produced byCONFIG GET) from aListtoProperties.static <K,V> org.springframework.core.convert.converter.Converter<Map<K, V>, Properties> Returns a converter to convert fromMaptoProperties.static longmillisecondsToTimeUnit(long milliseconds, TimeUnit targetUnit) Convertsmillisecondsto the givenTimeUnit.millisecondsToTimeUnit(TimeUnit timeUnit) Creates a newConverterto convert from milliseconds to the givenTimeUnit.static <T> TParse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion ofbyte[]andByteBuffer.static ObjectParse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion ofbyte[]andByteBufferbased on the sourcePath and a typeHintMapstatic DurationsecondsToDuration(Long seconds) Convert the given nullable seconds to aDurationor null.static longsecondsToTimeUnit(long seconds, TimeUnit targetUnit) Convertssecondsto the givenTimeUnit.secondsToTimeUnit(TimeUnit timeUnit) Creates a newConverterto convert from seconds to the givenTimeUnit.static BooleanstringToBoolean(String source) static org.springframework.core.convert.converter.Converter<String,Properties> static byte[]static Booleanprotected static RedisClusterNodetoClusterNode(String clusterNodesLine) Converts the result of a single line ofCLUSTER NODESinto aRedisClusterNode.static DataTypetoDataType(String source) static PropertiestoProperties(String source) static PropertiestoProperties(List<String> input) Converts array outputs with key-value sequences (such as produced byCONFIG GET) from aListtoProperties.static PropertiestoProperties(Map<?, ?> source) static Set<RedisClusterNode>toSetOfRedisClusterNodes(String clusterNodes) Converts the result ofCLUSTER NODESintoRedisClusterNodes.static Set<RedisClusterNode>toSetOfRedisClusterNodes(Collection<String> lines) Converts lines from the result ofCLUSTER NODESintoRedisClusterNodes.static LongtoTimeMillis(String seconds, String microseconds) Returns the timestamp constructed from the givensecondsandmicroseconds.static LongtoTimeMillis(String seconds, String microseconds, TimeUnit unit) Returns the timestamp constructed from the givensecondsandmicroseconds.
-
Constructor Details
-
Converters
public Converters()
-
-
Method Details
-
identityConverter
public static <T> org.springframework.core.convert.converter.Converter<T,T> identityConverter()Returns aConverterthat 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
-
stringToBooleanConverter
-
stringToProps
public static org.springframework.core.convert.converter.Converter<String,Properties> stringToProps() -
longToBoolean
-
stringToDataType
-
toProperties
-
toProperties
-
toBoolean
-
toDataType
-
toBit
-
toClusterNode
Converts the result of a single line ofCLUSTER NODESinto aRedisClusterNode.- Parameters:
clusterNodesLine-- Returns:
- Since:
- 1.7
-
toSetOfRedisClusterNodes
Converts lines from the result ofCLUSTER NODESintoRedisClusterNodes.- Parameters:
lines-- Returns:
- Since:
- 1.7
-
toSetOfRedisClusterNodes
Converts the result ofCLUSTER NODESintoRedisClusterNodes.- Parameters:
clusterNodes-- Returns:
- Since:
- 1.7
-
toObjects
-
toTimeMillis
Returns the timestamp constructed from the givensecondsandmicroseconds.- Parameters:
seconds- server time in secondsmicroseconds- elapsed microseconds in current second- Returns:
-
toTimeMillis
Returns the timestamp constructed from the givensecondsandmicroseconds.- Parameters:
seconds- server time in seconds.microseconds- elapsed microseconds in current second.unit- target unit.- Returns:
- Since:
- 2.5
-
secondsToTimeUnit
Convertssecondsto the givenTimeUnit.- Parameters:
seconds-targetUnit- must not be null.- Returns:
- Since:
- 1.8
-
secondsToTimeUnit
public static org.springframework.core.convert.converter.Converter<Long,Long> secondsToTimeUnit(TimeUnit timeUnit) Creates a newConverterto convert from seconds to the givenTimeUnit.- Parameters:
timeUnit- muist not be null.- Returns:
- Since:
- 1.8
-
millisecondsToTimeUnit
Convertsmillisecondsto the givenTimeUnit.- Parameters:
milliseconds-targetUnit- must not be null.- Returns:
- Since:
- 1.8
-
millisecondsToTimeUnit
public static org.springframework.core.convert.converter.Converter<Long,Long> millisecondsToTimeUnit(TimeUnit timeUnit) Creates a newConverterto convert from milliseconds to the givenTimeUnit.- Parameters:
timeUnit- must not be null.- Returns:
- Since:
- 1.8
-
deserializingGeoResultsConverter
public static <V> org.springframework.core.convert.converter.Converter<org.springframework.data.geo.GeoResults<RedisGeoCommands.GeoLocation<byte[]>>,org.springframework.data.geo.GeoResults<RedisGeoCommands.GeoLocation<V>>> deserializingGeoResultsConverter(RedisSerializer<V> serializer) Convertercapable of deserializingGeoResults.- Parameters:
serializer-- Returns:
- Since:
- 1.8
-
distanceConverterForMetric
public static org.springframework.core.convert.converter.Converter<Double,org.springframework.data.geo.Distance> distanceConverterForMetric(org.springframework.data.geo.Metric metric) Convertercapable of converting Double intoDistanceusing givenMetric.- Parameters:
metric-- Returns:
- Since:
- 1.8
-
toProperties
Converts array outputs with key-value sequences (such as produced byCONFIG GET) from aListtoProperties.- Parameters:
input- must not be null.- Returns:
- the mapped result.
- Since:
- 2.0
-
listToPropertiesConverter
public static org.springframework.core.convert.converter.Converter<List<String>,Properties> listToPropertiesConverter()Returns a converter to convert array outputs with key-value sequences (such as produced byCONFIG GET) from aListtoProperties.- Returns:
- the converter.
- Since:
- 2.0
-
mapToPropertiesConverter
public static <K,V> org.springframework.core.convert.converter.Converter<Map<K,V>, mapToPropertiesConverter()Properties> Returns a converter to convert fromMaptoProperties.- Returns:
- the converter.
- Since:
- 2.0
-
secondsToDuration
Convert the given nullable seconds to aDurationor null.- Parameters:
seconds- can be null.- Returns:
- given seconds as
Durationor null. - Since:
- 2.1
-
parse
Parse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion ofbyte[]andByteBuffer. -
parse
Parse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion ofbyte[]andByteBufferbased on the sourcePath and a typeHintMap- Parameters:
source- the source to parsesourcePath- the current path (use "root", for level 0).typeHintMap- source path to target type hints allowing wildcards (*).- Returns:
- Since:
- 2.3
-
entryOf
- Type Parameters:
K-V-- Parameters:
key-value-- Returns:
- Since:
- 2.6
-