DATAREDIS-1095 - Use Flux.usingWhen(…) in DefaultReactiveScriptExecutor.execute(…).

We now consistently use Flux.usingWhen(…) to obtain and release Redis connections without blocking the calling thread.

Original Pull Request: #509
This commit is contained in:
Mark Paluch
2020-02-05 15:12:19 +01:00
committed by Christoph Strobl
parent b3d54a3684
commit 87bbee4310
2 changed files with 11 additions and 10 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.data.redis.core.script;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.nio.ByteBuffer;
import java.util.List;
@@ -161,15 +162,9 @@ public class DefaultReactiveScriptExecutor<K> implements ReactiveScriptExecutor<
Assert.notNull(action, "Callback object must not be null");
ReactiveRedisConnectionFactory factory = getConnectionFactory();
ReactiveRedisConnection conn = factory.getReactiveConnection();
try {
return Flux.defer(() -> action.doInRedis(conn)).doFinally(signal -> conn.close());
} catch (RuntimeException e) {
conn.close();
throw e;
}
return Flux.usingWhen(Mono.fromSupplier(factory::getReactiveConnection), action::doInRedis,
ReactiveRedisConnection::closeLater);
}
public ReactiveRedisConnectionFactory getConnectionFactory() {