Skip to content

Commit 143c452

Browse files
DATAREDIS-711 - Polishing.
Retain publisher sequence by using concatMap, remove trailing whitespace, flush script cache in tests. Original Pull Request: #282
1 parent a99a738 commit 143c452

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public Flux<CommandResponse<KeyCommand, Flux<Map.Entry<ByteBuffer, ByteBuffer>>>
222222
@Override
223223
public Flux<NumericResponse<HStrLenCommand, Long>> hStrLen(Publisher<HStrLenCommand> commands) {
224224

225-
return connection.execute(cmd -> Flux.from(commands).flatMap(command -> {
225+
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
226226

227227
Assert.notNull(command.getKey(), "Key must not be null!");
228228
Assert.notNull(command.getField(), "Field must not be null!");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* Creates a specific client configuration for Lettuce tests.
26-
*
26+
*
2727
* @author Mark Paluch
2828
*/
2929
public class LettuceTestClientConfiguration {

src/test/java/org/springframework/data/redis/core/script/DefaultReactiveScriptExecutorTests.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.util.Collections;
2525
import java.util.List;
2626

27+
import org.junit.After;
2728
import org.junit.AfterClass;
28-
import org.junit.Before;
2929
import org.junit.BeforeClass;
3030
import org.junit.Test;
3131
import org.springframework.core.io.ClassPathResource;
@@ -35,6 +35,7 @@
3535
import org.springframework.data.redis.connection.RedisConnectionFactory;
3636
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
3737
import org.springframework.data.redis.connection.lettuce.LettuceTestClientConfiguration;
38+
import org.springframework.data.redis.core.RedisCallback;
3839
import org.springframework.data.redis.core.RedisTemplate;
3940
import org.springframework.data.redis.core.StringRedisTemplate;
4041
import org.springframework.data.redis.serializer.GenericToStringSerializer;
@@ -48,6 +49,7 @@
4849

4950
/**
5051
* @author Mark Paluch
52+
* @author Christoph Strobl
5153
*/
5254
public class DefaultReactiveScriptExecutorTests {
5355

@@ -74,12 +76,16 @@ public static void cleanUp() {
7476
}
7577
}
7678

77-
@Before
78-
public void before() {
79+
@After
80+
public void tearDown() {
7981

8082
RedisConnection connection = connectionFactory.getConnection();
81-
connection.flushDb();
82-
connection.close();
83+
try {
84+
connection.scriptingCommands().scriptFlush();
85+
connection.flushDb();
86+
} finally {
87+
connection.close();
88+
}
8389
}
8490

8591
protected RedisConnectionFactory getConnectionFactory() {
@@ -217,15 +223,25 @@ public void shouldApplyCustomResultSerializer() {
217223
}
218224

219225
@Test // DATAREDIS-711
220-
public void testExecuteCachedNullKeys() {
226+
public void executeAddsScriptToScriptCache() {
221227

222228
DefaultRedisScript<String> script = new DefaultRedisScript<>();
223229
script.setScriptText("return 'HELLO'");
224230
script.setResultType(String.class);
225231

226232
// Execute script twice, second time should be from cache
233+
234+
assertThat(stringTemplate.execute(
235+
(RedisCallback<List<Boolean>>) connection -> connection.scriptingCommands().scriptExists(script.getSha1())))
236+
.containsExactly(false);
237+
227238
StepVerifier.create(stringScriptExecutor.execute(script, Collections.emptyList())).expectNext("HELLO")
228239
.verifyComplete();
240+
241+
assertThat(stringTemplate.execute(
242+
(RedisCallback<List<Boolean>>) connection -> connection.scriptingCommands().scriptExists(script.getSha1())))
243+
.containsExactly(true);
244+
229245
StepVerifier.create(stringScriptExecutor.execute(script, Collections.emptyList())).expectNext("HELLO")
230246
.verifyComplete();
231247
}

0 commit comments

Comments
 (0)