@@ -151,6 +151,14 @@ public <T> Flux<T> execute(ReactiveRedisCallback<T> action, boolean exposeConnec
151
151
return Flux .from (doInConnection (action , exposeConnection ));
152
152
}
153
153
154
+ @ Override
155
+ public <T > Flux <T > executeInSession (ReactiveRedisSessionCallback <K , V , T > action ) {
156
+
157
+ Assert .notNull (action , "Callback object must not be null" );
158
+ return Flux
159
+ .from (doInConnection (connection -> action .doWithOperations (withConnection (connection )), exposeConnection ));
160
+ }
161
+
154
162
/**
155
163
* Create a reusable Flux for a {@link ReactiveRedisCallback}. Callback is executed within a connection context. The
156
164
* connection is released outside the callback.
@@ -188,7 +196,7 @@ public <T> Mono<T> createMono(ReactiveRedisCallback<T> callback) {
188
196
* @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code
189
197
* @return object returned by the action
190
198
*/
191
- private <T > Publisher <T > doInConnection (ReactiveRedisCallback <T > action , boolean exposeConnection ) {
199
+ <T > Publisher <T > doInConnection (ReactiveRedisCallback <T > action , boolean exposeConnection ) {
192
200
193
201
Assert .notNull (action , "Callback object must not be null" );
194
202
@@ -742,6 +750,31 @@ public RedisSerializationContext<K, V> getSerializationContext() {
742
750
return serializationContext ;
743
751
}
744
752
753
+ private ReactiveRedisOperations <K , V > withConnection (ReactiveRedisConnection connection ) {
754
+ return new BoundConnectionRedisTemplate (connection , connectionFactory , serializationContext );
755
+ }
756
+
757
+ class BoundConnectionRedisTemplate extends ReactiveRedisTemplate <K , V > {
758
+
759
+ private final ReactiveRedisConnection connection ;
760
+
761
+ public BoundConnectionRedisTemplate (ReactiveRedisConnection connection ,
762
+ ReactiveRedisConnectionFactory connectionFactory , RedisSerializationContext <K , V > serializationContext ) {
763
+ super (connectionFactory , serializationContext , true );
764
+ this .connection = connection ;
765
+ }
766
+
767
+ @ Override
768
+ <T > Publisher <T > doInConnection (ReactiveRedisCallback <T > action , boolean exposeConnection ) {
769
+
770
+ Assert .notNull (action , "Callback object must not be null" );
771
+
772
+ ReactiveRedisConnection connToUse = ReactiveRedisTemplate .this .preProcessConnection (connection , true );
773
+ Publisher <T > result = action .doInRedis (connToUse );
774
+ return ReactiveRedisTemplate .this .postProcessResult (result , connToUse , true );
775
+ }
776
+ }
777
+
745
778
private ByteBuffer rawKey (K key ) {
746
779
return getSerializationContext ().getKeySerializationPair ().getWriter ().write (key );
747
780
}
0 commit comments