Skip to content

Extract creating of connection in ReactiveRedisTemplate into a separate method #2162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,29 @@ private <T> Publisher<T> doInConnection(ReactiveRedisCallback<T> action, boolean

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

return Flux.usingWhen(Mono.fromSupplier(() -> {

ReactiveRedisConnectionFactory factory = getConnectionFactory();
ReactiveRedisConnection conn = factory.getReactiveConnection();
ReactiveRedisConnection connToUse = preProcessConnection(conn, false);

return (exposeConnection ? connToUse : createRedisConnectionProxy(connToUse));
}), conn -> {
return Flux.usingWhen(getConnection(exposeConnection), conn -> {
Publisher<T> result = action.doInRedis(conn);

return postProcessResult(result, conn, false);

}, ReactiveRedisConnection::closeLater);
}

/**
* Creates a Mono which generates a new connection. The successors of {@link ReactiveRedisTemplate} might override
* the default behaviour.
*
* @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code
* return a {@link Mono} wrapping the {@link ReactiveRedisConnection}.
*/
protected Mono<ReactiveRedisConnection> getConnection(boolean exposeConnection) {
ReactiveRedisConnectionFactory factory = getConnectionFactory();
ReactiveRedisConnection conn = factory.getReactiveConnection();
ReactiveRedisConnection connToUse = preProcessConnection(conn, false);

return Mono.just(exposeConnection ? connToUse : createRedisConnectionProxy(connToUse));
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveRedisOperations#convertAndSend(java.lang.String, java.lang.Object)
Expand Down