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