Skip to content

Commit b939613

Browse files
committed
Polishing.
Use createMono/createFlux syntax instead of using the template for wrapper creation. See #2658 Original pull request: #2659
1 parent c7ded60 commit b939613

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/main/java/org/springframework/data/redis/core/DefaultReactiveGeoOperations.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.stream.Collectors;
2727

2828
import org.reactivestreams.Publisher;
29-
3029
import org.springframework.data.geo.Circle;
3130
import org.springframework.data.geo.Distance;
3231
import org.springframework.data.geo.GeoResult;
@@ -276,7 +275,7 @@ public Flux<GeoResult<GeoLocation<V>>> search(K key, GeoReference<V> reference,
276275
Assert.notNull(reference, "GeoReference must not be null");
277276
GeoReference<ByteBuffer> rawReference = getGeoReference(reference);
278277

279-
return template.doCreateFlux(connection -> connection.geoCommands()
278+
return createFlux(geoCommands -> geoCommands
280279
.geoSearch(rawKey(key), rawReference, geoPredicate, args).map(this::readGeoResult));
281280
}
282281

@@ -288,7 +287,7 @@ public Mono<Long> searchAndStore(K key, K destKey, GeoReference<V> reference,
288287
Assert.notNull(reference, "GeoReference must not be null");
289288
GeoReference<ByteBuffer> rawReference = getGeoReference(reference);
290289

291-
return template.doCreateMono(connection -> connection.geoCommands().geoSearchStore(rawKey(destKey), rawKey(key),
290+
return createMono(geoCommands -> geoCommands.geoSearchStore(rawKey(destKey), rawKey(key),
292291
rawReference, geoPredicate, args));
293292
}
294293

src/main/java/org/springframework/data/redis/core/DefaultReactiveHashOperations.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.function.Function;
2727

2828
import org.reactivestreams.Publisher;
29-
3029
import org.springframework.data.redis.connection.ReactiveHashCommands;
3130
import org.springframework.data.redis.connection.convert.Converters;
3231
import org.springframework.data.redis.serializer.RedisSerializationContext;
@@ -127,26 +126,23 @@ public Mono<HK> randomKey(H key) {
127126

128127
Assert.notNull(key, "Key must not be null");
129128

130-
return template.doCreateMono(connection -> connection //
131-
.hashCommands().hRandField(rawKey(key))).map(this::readHashKey);
129+
return createMono(hashCommands -> hashCommands.hRandField(rawKey(key))).map(this::readHashKey);
132130
}
133131

134132
@Override
135133
public Mono<Map.Entry<HK, HV>> randomEntry(H key) {
136134

137135
Assert.notNull(key, "Key must not be null");
138136

139-
return template.doCreateMono(connection -> connection //
140-
.hashCommands().hRandFieldWithValues(rawKey(key))).map(this::deserializeHashEntry);
137+
return createMono(hashCommands ->hashCommands.hRandFieldWithValues(rawKey(key))).map(this::deserializeHashEntry);
141138
}
142139

143140
@Override
144141
public Flux<HK> randomKeys(H key, long count) {
145142

146143
Assert.notNull(key, "Key must not be null");
147144

148-
return template.doCreateFlux(connection -> connection //
149-
.hashCommands().hRandField(rawKey(key), count)).map(this::readHashKey);
145+
return createFlux(hashCommands -> hashCommands.hRandField(rawKey(key), count)).map(this::readHashKey);
150146
}
151147

152148
@Override

src/main/java/org/springframework/data/redis/core/DefaultReactiveValueOperations.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.reactivestreams.Publisher;
3030
import org.springframework.data.redis.connection.BitFieldSubCommands;
31+
import org.springframework.data.redis.connection.ReactiveNumberCommands;
3132
import org.springframework.data.redis.connection.ReactiveStringCommands;
3233
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
3334
import org.springframework.data.redis.core.types.Expiration;
@@ -200,39 +201,39 @@ public Mono<Long> increment(K key) {
200201

201202
Assert.notNull(key, "Key must not be null");
202203

203-
return template.doCreateMono(connection -> connection.numberCommands().incr(rawKey(key)));
204+
return createNumericMono(numberCommands -> numberCommands.incr(rawKey(key)));
204205
}
205206

206207
@Override
207208
public Mono<Long> increment(K key, long delta) {
208209

209210
Assert.notNull(key, "Key must not be null");
210211

211-
return template.doCreateMono(connection -> connection.numberCommands().incrBy(rawKey(key), delta));
212+
return createNumericMono(numberCommands -> numberCommands.incrBy(rawKey(key), delta));
212213
}
213214

214215
@Override
215216
public Mono<Double> increment(K key, double delta) {
216217

217218
Assert.notNull(key, "Key must not be null");
218219

219-
return template.doCreateMono(connection -> connection.numberCommands().incrBy(rawKey(key), delta));
220+
return createNumericMono(numberCommands -> numberCommands.incrBy(rawKey(key), delta));
220221
}
221222

222223
@Override
223224
public Mono<Long> decrement(K key) {
224225

225226
Assert.notNull(key, "Key must not be null");
226227

227-
return template.doCreateMono(connection -> connection.numberCommands().decr(rawKey(key)));
228+
return createNumericMono(numberCommands -> numberCommands.decr(rawKey(key)));
228229
}
229230

230231
@Override
231232
public Mono<Long> decrement(K key, long delta) {
232233

233234
Assert.notNull(key, "Key must not be null");
234235

235-
return template.doCreateMono(connection -> connection.numberCommands().decrBy(rawKey(key), delta));
236+
return createNumericMono(numberCommands -> numberCommands.decrBy(rawKey(key), delta));
236237
}
237238

238239
@Override
@@ -303,6 +304,13 @@ public Mono<Boolean> delete(K key) {
303304
return template.doCreateMono(connection -> connection.keyCommands().del(rawKey(key))).map(l -> l != 0);
304305
}
305306

307+
private <T> Mono<T> createNumericMono(Function<ReactiveNumberCommands, Publisher<T>> function) {
308+
309+
Assert.notNull(function, "Function must not be null");
310+
311+
return template.doCreateMono(connection -> function.apply(connection.numberCommands()));
312+
}
313+
306314
private <T> Mono<T> createMono(Function<ReactiveStringCommands, Publisher<T>> function) {
307315

308316
Assert.notNull(function, "Function must not be null");

0 commit comments

Comments
 (0)