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:
committed by
Christoph Strobl
parent
b3d54a3684
commit
87bbee4310
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user