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
-
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) Converter
capable of deserializingGeoResults
.static org.springframework.core.convert.converter.Converter<Double,
org.springframework.data.geo.Distance> distanceConverterForMetric
(org.springframework.data.geo.Metric metric) Converter
capable of converting Double intoDistance
using givenMetric
.static <K,
V> Map.Entry<K, V> entryOf
(K key, V value) static <T> org.springframework.core.convert.converter.Converter<T,
T> Returns aConverter
that 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 aList
toProperties
.static <K,
V> org.springframework.core.convert.converter.Converter<Map<K, V>, Properties> Returns a converter to convert fromMap
toProperties
.static long
millisecondsToTimeUnit
(long milliseconds, TimeUnit targetUnit) Convertsmilliseconds
to the givenTimeUnit
.millisecondsToTimeUnit
(TimeUnit timeUnit) Creates a newConverter
to convert from milliseconds to the givenTimeUnit
.static <T> T
Parse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion ofbyte[]
andByteBuffer
.static Object
Parse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion ofbyte[]
andByteBuffer
based on the sourcePath and a typeHintMapstatic Duration
secondsToDuration
(Long seconds) Convert the given nullable seconds to aDuration
or null.static long
secondsToTimeUnit
(long seconds, TimeUnit targetUnit) Convertsseconds
to the givenTimeUnit
.secondsToTimeUnit
(TimeUnit timeUnit) Creates a newConverter
to convert from seconds to the givenTimeUnit
.static Boolean
stringToBoolean
(String source) static org.springframework.core.convert.converter.Converter<String,
Properties> static byte[]
static Boolean
protected static RedisClusterNode
toClusterNode
(String clusterNodesLine) Converts the result of a single line ofCLUSTER NODES
into aRedisClusterNode
.static DataType
toDataType
(String source) static Properties
toProperties
(String source) static Properties
toProperties
(List<String> input) Converts array outputs with key-value sequences (such as produced byCONFIG GET
) from aList
toProperties
.static Properties
toProperties
(Map<?, ?> source) static Set<RedisClusterNode>
toSetOfRedisClusterNodes
(String clusterNodes) Converts the result ofCLUSTER NODES
intoRedisClusterNode
s.static Set<RedisClusterNode>
toSetOfRedisClusterNodes
(Collection<String> lines) Converts lines from the result ofCLUSTER NODES
intoRedisClusterNode
s.static Long
toTimeMillis
(String seconds, String microseconds) Returns the timestamp constructed from the givenseconds
andmicroseconds
.static Long
toTimeMillis
(String seconds, String microseconds, TimeUnit unit) Returns the timestamp constructed from the givenseconds
andmicroseconds
.
-
Constructor Details
-
Converters
public Converters()
-
-
Method Details
-
identityConverter
public static <T> org.springframework.core.convert.converter.Converter<T,T> identityConverter()Returns aConverter
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
-
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 NODES
into aRedisClusterNode
.- Parameters:
clusterNodesLine
-- Returns:
- Since:
- 1.7
-
toSetOfRedisClusterNodes
Converts lines from the result ofCLUSTER NODES
intoRedisClusterNode
s.- Parameters:
lines
-- Returns:
- Since:
- 1.7
-
toSetOfRedisClusterNodes
Converts the result ofCLUSTER NODES
intoRedisClusterNode
s.- Parameters:
clusterNodes
-- Returns:
- Since:
- 1.7
-
toObjects
-
toTimeMillis
Returns the timestamp constructed from the givenseconds
andmicroseconds
.- Parameters:
seconds
- server time in secondsmicroseconds
- elapsed microseconds in current second- Returns:
-
toTimeMillis
Returns the timestamp constructed from the givenseconds
andmicroseconds
.- Parameters:
seconds
- server time in seconds.microseconds
- elapsed microseconds in current second.unit
- target unit.- Returns:
- Since:
- 2.5
-
secondsToTimeUnit
Convertsseconds
to 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 newConverter
to convert from seconds to the givenTimeUnit
.- Parameters:
timeUnit
- muist not be null.- Returns:
- Since:
- 1.8
-
millisecondsToTimeUnit
Convertsmilliseconds
to 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 newConverter
to 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) Converter
capable 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) Converter
capable of converting Double intoDistance
using givenMetric
.- Parameters:
metric
-- Returns:
- Since:
- 1.8
-
toProperties
Converts array outputs with key-value sequences (such as produced byCONFIG GET
) from aList
toProperties
.- 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 aList
toProperties
.- 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 fromMap
toProperties
.- Returns:
- the converter.
- Since:
- 2.0
-
secondsToDuration
Convert the given nullable seconds to aDuration
or null.- Parameters:
seconds
- can be null.- Returns:
- given seconds as
Duration
or 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[]
andByteBuffer
based 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
-