From d37341e7f6a56a9b2d2f2eac6fa1da78ffc8e41a Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 13 Sep 2021 15:01:43 +0200 Subject: [PATCH] Polishing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add author and since tags. Wrap connection allocation with fromSupplier(…). Move connection proxy decoration into doInConnection(…) as connection decoration isn't directly related to connection creation. See #2145 Original pull request: #2162. --- .../redis/core/ReactiveRedisTemplate.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java b/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java index a534e4539..ab7bc1103 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java @@ -58,6 +58,7 @@ import org.springframework.util.ClassUtils; * * @author Mark Paluch * @author Christoph Strobl + * @author Petromir Dzhunev * @since 2.0 * @param the Redis key type against which the template works (usually a String) * @param the Redis value type against which the template works @@ -192,7 +193,14 @@ public class ReactiveRedisTemplate implements ReactiveRedisOperations { + Mono connection = getConnection(); + + if (!exposeConnection) { + connection = connection.map(this::createRedisConnectionProxy); + } + + return Flux.usingWhen(connection, conn -> { + Publisher result = action.doInRedis(conn); return postProcessResult(result, conn, false); @@ -201,18 +209,16 @@ public class ReactiveRedisTemplate implements ReactiveRedisOperations getConnection(boolean exposeConnection) { - ReactiveRedisConnectionFactory factory = getConnectionFactory(); - ReactiveRedisConnection conn = factory.getReactiveConnection(); - ReactiveRedisConnection connToUse = preProcessConnection(conn, false); + protected Mono getConnection() { - return Mono.just(exposeConnection ? connToUse : createRedisConnectionProxy(connToUse)); + ReactiveRedisConnectionFactory factory = getConnectionFactory(); + + return Mono.fromSupplier(() -> preProcessConnection(factory.getReactiveConnection(), false)); } /*