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
@@ -232,7 +233,14 @@ <T> Publisher<T> doInConnection(ReactiveRedisCallback<T> action, boolean exposeC
232233
233234 Assert .notNull (action , "Callback object must not be null" );
234235
235- return Flux .usingWhen (getConnection (exposeConnection ), conn -> {
236+ Mono <ReactiveRedisConnection > connection = getConnection ();
237+
238+ if (!exposeConnection ) {
239+ connection = connection .map (this ::createRedisConnectionProxy );
240+ }
241+
242+ return Flux .usingWhen (connection , conn -> {
243+
236244 Publisher <T > result = action .doInRedis (conn );
237245
238246 return postProcessResult (result , conn , false );
@@ -241,18 +249,16 @@ <T> Publisher<T> doInConnection(ReactiveRedisCallback<T> action, boolean exposeC
241249 }
242250
243251 /**
244- * Creates a Mono which generates a new connection. The successors of {@link ReactiveRedisTemplate} might override
245- * the default behaviour .
252+ * Creates a {@link Mono} which emits a new {@link ReactiveRedisConnection}. Can be overridden in subclasses to
253+ * provide a different mechanism for connection allocation for the given method .
246254 *
247- * @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code
248- * return a {@link Mono} wrapping the {@link ReactiveRedisConnection}.
255+ * @since 2.5.5
249256 */
250- protected Mono <ReactiveRedisConnection > getConnection (boolean exposeConnection ) {
257+ protected Mono <ReactiveRedisConnection > getConnection () {
258+
251259 ReactiveRedisConnectionFactory factory = getConnectionFactory ();
252- ReactiveRedisConnection conn = factory .getReactiveConnection ();
253- ReactiveRedisConnection connToUse = preProcessConnection (conn , false );
254260
255- return Mono .just ( exposeConnection ? connToUse : createRedisConnectionProxy ( connToUse ));
261+ return Mono .fromSupplier (() -> preProcessConnection ( factory . getReactiveConnection (), false ));
256262 }
257263
258264 /*
0 commit comments