Skip to content

Commit b0d139a

Browse files
committed
DATAREDIS-665 - Upgrade to Lettuce 5.0 RC1.
Adapt to changes in Lettuce API.
1 parent 54ba6e3 commit b0d139a

File tree

8 files changed

+26
-19
lines changed

8 files changed

+26
-19
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<beanutils>1.9.2</beanutils>
2222
<xstream>1.4.8</xstream>
2323
<pool>2.2</pool>
24-
<lettuce>5.0.0.M2</lettuce>
24+
<lettuce>5.0.0.RC1</lettuce>
2525
<jedis>2.9.0</jedis>
2626
<multithreadedtc>1.01</multithreadedtc>
2727
</properties>

src/main/java/org/springframework/data/redis/connection/convert/Converters.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,16 @@ public static Converter<List<String>, Properties> listToPropertiesConverter() {
408408
return STRING_LIST_TO_PROPERTIES_CONVERTER;
409409
}
410410

411+
/**
412+
* Returns a converter to convert from {@link Map} to {@link Properties}.
413+
*
414+
* @return the converter.
415+
* @since 2.0
416+
*/
417+
public static Converter<Map<?, ?>, Properties> mapToPropertiesConverter() {
418+
return MAP_TO_PROPERTIES;
419+
}
420+
411421
/**
412422
* @author Christoph Strobl
413423
* @since 1.8

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.Collection;
2222
import java.util.List;
23+
import java.util.Map;
2324
import java.util.Map.Entry;
2425
import java.util.Properties;
2526

@@ -228,20 +229,18 @@ public void shutdown(RedisClusterNode node) {
228229
@Override
229230
public Properties getConfig(final String pattern) {
230231

231-
List<NodeResult<List<String>>> mapResult = executeCommandOnAllNodes(client -> client.configGet(pattern))
232+
List<NodeResult<Map<String, String>>> mapResult = executeCommandOnAllNodes(client -> client.configGet(pattern))
232233
.getResults();
233234

234-
List<String> result = new ArrayList<>();
235-
for (NodeResult<List<String>> entry : mapResult) {
235+
Properties properties = new Properties();
236+
237+
for (NodeResult<Map<String, String>> entry : mapResult) {
236238

237239
String prefix = entry.getNode().asString();
238-
int i = 0;
239-
for (String value : entry.getValue()) {
240-
result.add((i++ % 2 == 0 ? (prefix + ".") : "") + value);
241-
}
240+
entry.getValue().forEach((key, value) -> properties.setProperty(prefix + "." + key, value));
242241
}
243242

244-
return Converters.toProperties(result);
243+
return properties;
245244
}
246245

247246
/*

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,7 @@ private AbstractRedisClient createRedisClient() {
767767
.map(clientResources -> RedisClusterClient.create(clientResources, initialUris)) //
768768
.orElseGet(() -> RedisClusterClient.create(initialUris));
769769

770-
this.clusterCommandExecutor = new ClusterCommandExecutor(
771-
new LettuceClusterTopologyProvider(clusterClient),
770+
this.clusterCommandExecutor = new ClusterCommandExecutor(new LettuceClusterTopologyProvider(clusterClient),
772771
new LettuceClusterConnection.LettuceClusterNodeResourceProvider(clusterClient), EXCEPTION_TRANSLATION);
773772

774773
clientConfiguration.getClientOptions() //
@@ -795,6 +794,7 @@ private RedisURI getSentinelRedisURI() {
795794
RedisURI redisUri = LettuceConverters.sentinelConfigurationToRedisURI(sentinelConfiguration);
796795

797796
getRedisPassword().toOptional().ifPresent(redisUri::setPassword);
797+
redisUri.setTimeout(clientConfiguration.getCommandTimeout());
798798

799799
return redisUri;
800800
}
@@ -808,7 +808,7 @@ private RedisURI createRedisURIAndApplySettings(String host, int port) {
808808
builder.withSsl(clientConfiguration.isUseSsl());
809809
builder.withVerifyPeer(clientConfiguration.isVerifyPeer());
810810
builder.withStartTls(clientConfiguration.isStartTls());
811-
builder.withTimeout(clientConfiguration.getCommandTimeout().toMillis(), TimeUnit.MILLISECONDS);
811+
builder.withTimeout(clientConfiguration.getCommandTimeout());
812812

813813
return builder.build();
814814
}

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public Mono<Properties> getConfig(RedisClusterNode node, String pattern) {
205205

206206
Assert.hasText(pattern, "Pattern must not be null nor empty!");
207207

208-
return connection.execute(node, c -> c.configGet(pattern).collectList()) //
208+
return connection.execute(node, c -> c.configGet(pattern)) //
209209
.map(LettuceConverters::toProperties) //
210210
.next();
211211
}

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public Mono<Properties> getConfig(String pattern) {
149149

150150
Assert.hasText(pattern, "Pattern must not be null nor empty!");
151151

152-
return connection.execute(c -> c.configGet(pattern).collectList()) //
152+
return connection.execute(c -> c.configGet(pattern)) //
153153
.map(LettuceConverters::toProperties).next();
154154
}
155155

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,12 @@ public Properties getConfig(String param) {
281281
try {
282282
if (isPipelined()) {
283283
pipeline(
284-
connection.newLettuceResult(getAsyncConnection().configGet(param), Converters.listToPropertiesConverter()));
284+
connection.newLettuceResult(getAsyncConnection().configGet(param), Converters.mapToPropertiesConverter()));
285285
return null;
286286
}
287287
if (isQueueing()) {
288288
transaction(
289-
connection.newLettuceTxResult(getConnection().configGet(param), Converters.listToPropertiesConverter()));
289+
connection.newLettuceTxResult(getConnection().configGet(param), Converters.mapToPropertiesConverter()));
290290
return null;
291291
}
292292
return Converters.toProperties(getConnection().configGet(param));

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.security.NoSuchAlgorithmException;
3535
import java.time.Duration;
3636
import java.util.Collections;
37-
import java.util.concurrent.TimeUnit;
3837

3938
import org.junit.After;
4039
import org.junit.Before;
@@ -93,8 +92,7 @@ public void timeoutShouldBeSetCorrectlyOnClusterClient() {
9392
Iterable<RedisURI> initialUris = (Iterable<RedisURI>) getField(client, "initialUris");
9493

9594
for (RedisURI uri : initialUris) {
96-
assertThat(uri.getTimeout(), is(equalTo(connectionFactory.getTimeout())));
97-
assertThat(uri.getUnit(), is(equalTo(TimeUnit.MILLISECONDS)));
95+
assertThat(uri.getTimeout(), is(equalTo(Duration.ofMillis(connectionFactory.getTimeout()))));
9896
}
9997
}
10098

0 commit comments

Comments
 (0)