Skip to content

Commit aaf7818

Browse files
petromirmp911de
authored andcommitted
Extract connection creation into ReactiveRedisTemplate.getConnection() method.
A new method, called getConnection, is introduced to allow overriding of connection creation. Closes #2145 Original pull request: #2162.
1 parent cb20f8a commit aaf7818

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,29 @@ <T> Publisher<T> doInConnection(ReactiveRedisCallback<T> action, boolean exposeC
232232

233233
Assert.notNull(action, "Callback object must not be null");
234234

235-
return Flux.usingWhen(Mono.fromSupplier(() -> {
236-
237-
ReactiveRedisConnectionFactory factory = getConnectionFactory();
238-
ReactiveRedisConnection conn = factory.getReactiveConnection();
239-
ReactiveRedisConnection connToUse = preProcessConnection(conn, false);
240-
241-
return (exposeConnection ? connToUse : createRedisConnectionProxy(connToUse));
242-
}), conn -> {
235+
return Flux.usingWhen(getConnection(exposeConnection), conn -> {
243236
Publisher<T> result = action.doInRedis(conn);
244237

245238
return postProcessResult(result, conn, false);
246239

247240
}, ReactiveRedisConnection::closeLater);
248241
}
249242

243+
/**
244+
* Creates a Mono which generates a new connection. The successors of {@link ReactiveRedisTemplate} might override
245+
* the default behaviour.
246+
*
247+
* @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code
248+
* return a {@link Mono} wrapping the {@link ReactiveRedisConnection}.
249+
*/
250+
protected Mono<ReactiveRedisConnection> getConnection(boolean exposeConnection) {
251+
ReactiveRedisConnectionFactory factory = getConnectionFactory();
252+
ReactiveRedisConnection conn = factory.getReactiveConnection();
253+
ReactiveRedisConnection connToUse = preProcessConnection(conn, false);
254+
255+
return Mono.just(exposeConnection ? connToUse : createRedisConnectionProxy(connToUse));
256+
}
257+
250258
/*
251259
* (non-Javadoc)
252260
* @see org.springframework.data.redis.core.ReactiveRedisOperations#convertAndSend(java.lang.String, java.lang.Object)

0 commit comments

Comments
 (0)