Polishing.

Use createMono/createFlux syntax instead of using the template for wrapper creation.

See #2658
Original pull request: #2659
This commit is contained in:
Mark Paluch
2023-08-07 15:51:08 +02:00
parent 00737441fd
commit 0b32e7bed1
3 changed files with 18 additions and 15 deletions

View File

@@ -26,7 +26,6 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import org.reactivestreams.Publisher;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResult;
@@ -276,7 +275,7 @@ class DefaultReactiveGeoOperations<K, V> implements ReactiveGeoOperations<K, V>
Assert.notNull(reference, "GeoReference must not be null");
GeoReference<ByteBuffer> rawReference = getGeoReference(reference);
return template.doCreateFlux(connection -> connection.geoCommands()
return createFlux(geoCommands -> geoCommands
.geoSearch(rawKey(key), rawReference, geoPredicate, args).map(this::readGeoResult));
}
@@ -288,7 +287,7 @@ class DefaultReactiveGeoOperations<K, V> implements ReactiveGeoOperations<K, V>
Assert.notNull(reference, "GeoReference must not be null");
GeoReference<ByteBuffer> rawReference = getGeoReference(reference);
return template.doCreateMono(connection -> connection.geoCommands().geoSearchStore(rawKey(destKey), rawKey(key),
return createMono(geoCommands -> geoCommands.geoSearchStore(rawKey(destKey), rawKey(key),
rawReference, geoPredicate, args));
}

View File

@@ -26,7 +26,6 @@ import java.util.Map;
import java.util.function.Function;
import org.reactivestreams.Publisher;
import org.springframework.data.redis.connection.ReactiveHashCommands;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.serializer.RedisSerializationContext;
@@ -127,8 +126,7 @@ class DefaultReactiveHashOperations<H, HK, HV> implements ReactiveHashOperations
Assert.notNull(key, "Key must not be null");
return template.doCreateMono(connection -> connection //
.hashCommands().hRandField(rawKey(key))).map(this::readHashKey);
return createMono(hashCommands -> hashCommands.hRandField(rawKey(key))).map(this::readHashKey);
}
@Override
@@ -136,8 +134,7 @@ class DefaultReactiveHashOperations<H, HK, HV> implements ReactiveHashOperations
Assert.notNull(key, "Key must not be null");
return template.doCreateMono(connection -> connection //
.hashCommands().hRandFieldWithValues(rawKey(key))).map(this::deserializeHashEntry);
return createMono(hashCommands ->hashCommands.hRandFieldWithValues(rawKey(key))).map(this::deserializeHashEntry);
}
@Override
@@ -145,8 +142,7 @@ class DefaultReactiveHashOperations<H, HK, HV> implements ReactiveHashOperations
Assert.notNull(key, "Key must not be null");
return template.doCreateFlux(connection -> connection //
.hashCommands().hRandField(rawKey(key), count)).map(this::readHashKey);
return createFlux(hashCommands -> hashCommands.hRandField(rawKey(key), count)).map(this::readHashKey);
}
@Override

View File

@@ -28,6 +28,7 @@ import java.util.function.Function;
import org.reactivestreams.Publisher;
import org.springframework.data.redis.connection.BitFieldSubCommands;
import org.springframework.data.redis.connection.ReactiveNumberCommands;
import org.springframework.data.redis.connection.ReactiveStringCommands;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.core.types.Expiration;
@@ -200,7 +201,7 @@ class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K,
Assert.notNull(key, "Key must not be null");
return template.doCreateMono(connection -> connection.numberCommands().incr(rawKey(key)));
return createNumericMono(numberCommands -> numberCommands.incr(rawKey(key)));
}
@Override
@@ -208,7 +209,7 @@ class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K,
Assert.notNull(key, "Key must not be null");
return template.doCreateMono(connection -> connection.numberCommands().incrBy(rawKey(key), delta));
return createNumericMono(numberCommands -> numberCommands.incrBy(rawKey(key), delta));
}
@Override
@@ -216,7 +217,7 @@ class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K,
Assert.notNull(key, "Key must not be null");
return template.doCreateMono(connection -> connection.numberCommands().incrBy(rawKey(key), delta));
return createNumericMono(numberCommands -> numberCommands.incrBy(rawKey(key), delta));
}
@Override
@@ -224,7 +225,7 @@ class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K,
Assert.notNull(key, "Key must not be null");
return template.doCreateMono(connection -> connection.numberCommands().decr(rawKey(key)));
return createNumericMono(numberCommands -> numberCommands.decr(rawKey(key)));
}
@Override
@@ -232,7 +233,7 @@ class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K,
Assert.notNull(key, "Key must not be null");
return template.doCreateMono(connection -> connection.numberCommands().decrBy(rawKey(key), delta));
return createNumericMono(numberCommands -> numberCommands.decrBy(rawKey(key), delta));
}
@Override
@@ -303,6 +304,13 @@ class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K,
return template.doCreateMono(connection -> connection.keyCommands().del(rawKey(key))).map(l -> l != 0);
}
private <T> Mono<T> createNumericMono(Function<ReactiveNumberCommands, Publisher<T>> function) {
Assert.notNull(function, "Function must not be null");
return template.doCreateMono(connection -> function.apply(connection.numberCommands()));
}
private <T> Mono<T> createMono(Function<ReactiveStringCommands, Publisher<T>> function) {
Assert.notNull(function, "Function must not be null");