From b0d139af2e5ac581df6ede060177458679e50832 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 20 Jul 2017 15:51:04 +0200 Subject: [PATCH] DATAREDIS-665 - Upgrade to Lettuce 5.0 RC1. Adapt to changes in Lettuce API. --- pom.xml | 2 +- .../data/redis/connection/convert/Converters.java | 10 ++++++++++ .../lettuce/LettuceClusterServerCommands.java | 15 +++++++-------- .../lettuce/LettuceConnectionFactory.java | 6 +++--- .../LettuceReactiveClusterServerCommands.java | 2 +- .../lettuce/LettuceReactiveServerCommands.java | 2 +- .../connection/lettuce/LettuceServerCommands.java | 4 ++-- .../LettuceConnectionFactoryUnitTests.java | 4 +--- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 31a87026d..2406b4dd9 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 1.9.2 1.4.8 2.2 - 5.0.0.M2 + 5.0.0.RC1 2.9.0 1.01 diff --git a/src/main/java/org/springframework/data/redis/connection/convert/Converters.java b/src/main/java/org/springframework/data/redis/connection/convert/Converters.java index 9941a9c67..4d4c0dc26 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/Converters.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/Converters.java @@ -408,6 +408,16 @@ abstract public class Converters { return STRING_LIST_TO_PROPERTIES_CONVERTER; } + /** + * Returns a converter to convert from {@link Map} to {@link Properties}. + * + * @return the converter. + * @since 2.0 + */ + public static Converter, Properties> mapToPropertiesConverter() { + return MAP_TO_PROPERTIES; + } + /** * @author Christoph Strobl * @since 1.8 diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java index fa4b44640..28d37e90b 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java @@ -20,6 +20,7 @@ import io.lettuce.core.api.sync.RedisServerCommands; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.Properties; @@ -228,20 +229,18 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi @Override public Properties getConfig(final String pattern) { - List>> mapResult = executeCommandOnAllNodes(client -> client.configGet(pattern)) + List>> mapResult = executeCommandOnAllNodes(client -> client.configGet(pattern)) .getResults(); - List result = new ArrayList<>(); - for (NodeResult> entry : mapResult) { + Properties properties = new Properties(); + + for (NodeResult> entry : mapResult) { String prefix = entry.getNode().asString(); - int i = 0; - for (String value : entry.getValue()) { - result.add((i++ % 2 == 0 ? (prefix + ".") : "") + value); - } + entry.getValue().forEach((key, value) -> properties.setProperty(prefix + "." + key, value)); } - return Converters.toProperties(result); + return properties; } /* diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java index d81ed9986..6c0e4a3c3 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java @@ -767,8 +767,7 @@ public class LettuceConnectionFactory .map(clientResources -> RedisClusterClient.create(clientResources, initialUris)) // .orElseGet(() -> RedisClusterClient.create(initialUris)); - this.clusterCommandExecutor = new ClusterCommandExecutor( - new LettuceClusterTopologyProvider(clusterClient), + this.clusterCommandExecutor = new ClusterCommandExecutor(new LettuceClusterTopologyProvider(clusterClient), new LettuceClusterConnection.LettuceClusterNodeResourceProvider(clusterClient), EXCEPTION_TRANSLATION); clientConfiguration.getClientOptions() // @@ -795,6 +794,7 @@ public class LettuceConnectionFactory RedisURI redisUri = LettuceConverters.sentinelConfigurationToRedisURI(sentinelConfiguration); getRedisPassword().toOptional().ifPresent(redisUri::setPassword); + redisUri.setTimeout(clientConfiguration.getCommandTimeout()); return redisUri; } @@ -808,7 +808,7 @@ public class LettuceConnectionFactory builder.withSsl(clientConfiguration.isUseSsl()); builder.withVerifyPeer(clientConfiguration.isVerifyPeer()); builder.withStartTls(clientConfiguration.isStartTls()); - builder.withTimeout(clientConfiguration.getCommandTimeout().toMillis(), TimeUnit.MILLISECONDS); + builder.withTimeout(clientConfiguration.getCommandTimeout()); return builder.build(); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java index 1877ece49..9b21213f7 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java @@ -205,7 +205,7 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands Assert.hasText(pattern, "Pattern must not be null nor empty!"); - return connection.execute(node, c -> c.configGet(pattern).collectList()) // + return connection.execute(node, c -> c.configGet(pattern)) // .map(LettuceConverters::toProperties) // .next(); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommands.java index 5ab0453b5..2a04c1fda 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommands.java @@ -149,7 +149,7 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands { Assert.hasText(pattern, "Pattern must not be null nor empty!"); - return connection.execute(c -> c.configGet(pattern).collectList()) // + return connection.execute(c -> c.configGet(pattern)) // .map(LettuceConverters::toProperties).next(); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java index f610deeee..00823d7c8 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java @@ -281,12 +281,12 @@ class LettuceServerCommands implements RedisServerCommands { try { if (isPipelined()) { pipeline( - connection.newLettuceResult(getAsyncConnection().configGet(param), Converters.listToPropertiesConverter())); + connection.newLettuceResult(getAsyncConnection().configGet(param), Converters.mapToPropertiesConverter())); return null; } if (isQueueing()) { transaction( - connection.newLettuceTxResult(getConnection().configGet(param), Converters.listToPropertiesConverter())); + connection.newLettuceTxResult(getConnection().configGet(param), Converters.mapToPropertiesConverter())); return null; } return Converters.toProperties(getConnection().configGet(param)); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java index f516728e5..dda358492 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java @@ -34,7 +34,6 @@ import io.lettuce.core.resource.ClientResources; import java.security.NoSuchAlgorithmException; import java.time.Duration; import java.util.Collections; -import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; @@ -93,8 +92,7 @@ public class LettuceConnectionFactoryUnitTests { Iterable initialUris = (Iterable) getField(client, "initialUris"); for (RedisURI uri : initialUris) { - assertThat(uri.getTimeout(), is(equalTo(connectionFactory.getTimeout()))); - assertThat(uri.getUnit(), is(equalTo(TimeUnit.MILLISECONDS))); + assertThat(uri.getTimeout(), is(equalTo(Duration.ofMillis(connectionFactory.getTimeout())))); } }