Skip to content

Commit d37341e

Browse files
committed
Polishing.
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.
1 parent 7781c8f commit d37341e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Diff for: src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
*
5959
* @author Mark Paluch
6060
* @author Christoph Strobl
61+
* @author Petromir Dzhunev
6162
* @since 2.0
6263
* @param <K> the Redis key type against which the template works (usually a String)
6364
* @param <V> the Redis value type against which the template works
@@ -192,7 +193,14 @@ private <T> Publisher<T> doInConnection(ReactiveRedisCallback<T> action, boolean
192193

193194
Assert.notNull(action, "Callback object must not be null");
194195

195-
return Flux.usingWhen(getConnection(exposeConnection), conn -> {
196+
Mono<ReactiveRedisConnection> connection = getConnection();
197+
198+
if (!exposeConnection) {
199+
connection = connection.map(this::createRedisConnectionProxy);
200+
}
201+
202+
return Flux.usingWhen(connection, conn -> {
203+
196204
Publisher<T> result = action.doInRedis(conn);
197205

198206
return postProcessResult(result, conn, false);
@@ -201,18 +209,16 @@ private <T> Publisher<T> doInConnection(ReactiveRedisCallback<T> action, boolean
201209
}
202210

203211
/**
204-
* Creates a Mono which generates a new connection. The successors of {@link ReactiveRedisTemplate} might override
205-
* the default behaviour.
212+
* Creates a {@link Mono} which emits a new {@link ReactiveRedisConnection}. Can be overridden in subclasses to
213+
* provide a different mechanism for connection allocation for the given method.
206214
*
207-
* @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code
208-
* return a {@link Mono} wrapping the {@link ReactiveRedisConnection}.
215+
* @since 2.5.5
209216
*/
210-
protected Mono<ReactiveRedisConnection> getConnection(boolean exposeConnection) {
217+
protected Mono<ReactiveRedisConnection> getConnection() {
218+
211219
ReactiveRedisConnectionFactory factory = getConnectionFactory();
212-
ReactiveRedisConnection conn = factory.getReactiveConnection();
213-
ReactiveRedisConnection connToUse = preProcessConnection(conn, false);
214220

215-
return Mono.just(exposeConnection ? connToUse : createRedisConnectionProxy(connToUse));
221+
return Mono.fromSupplier(() -> preProcessConnection(factory.getReactiveConnection(), false));
216222
}
217223

218224
/*

0 commit comments

Comments
 (0)