Skip to content

Commit dc0756f

Browse files
committed
Polish for Issue #2655 and PR #2672.
See #2655 Original pull request: #2672
1 parent b5f124c commit dc0756f

13 files changed

+172
-80
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public Mono<Long> add(K key, Map<V, Point> memberCoordinateMap) {
9191

9292
Mono<List<GeoLocation<ByteBuffer>>> serializedList = Flux
9393
.fromIterable(() -> memberCoordinateMap.entrySet().iterator())
94-
.map(entry -> new GeoLocation<>(rawValue(entry.getKey()), entry.getValue())).collectList();
94+
.map(entry -> new GeoLocation<>(rawValue(entry.getKey()), entry.getValue()))
95+
.collectList();
9596

9697
return serializedList.flatMap(list -> geoCommands.geoAdd(rawKey(key), list));
9798
});
@@ -106,7 +107,8 @@ public Mono<Long> add(K key, Iterable<GeoLocation<V>> geoLocations) {
106107
return createMono(geoCommands -> {
107108

108109
Mono<List<GeoLocation<ByteBuffer>>> serializedList = Flux.fromIterable(geoLocations)
109-
.map(location -> new GeoLocation<>(rawValue(location.getName()), location.getPoint())).collectList();
110+
.map(location -> new GeoLocation<>(rawValue(location.getName()), location.getPoint()))
111+
.collectList();
110112

111113
return serializedList.flatMap(list -> geoCommands.geoAdd(rawKey(key), list));
112114
});
@@ -220,7 +222,7 @@ public Flux<GeoResult<GeoLocation<V>>> radius(K key, V member, double radius) {
220222

221223
return createFlux(geoCommands ->
222224
geoCommands.geoRadiusByMember(rawKey(key), rawValue(member), new Distance(radius)) //
223-
.map(this::readGeoResult));
225+
.map(this::readGeoResult));
224226
}
225227

226228
@Override
@@ -265,7 +267,7 @@ public Mono<Boolean> delete(K key) {
265267

266268
Assert.notNull(key, "Key must not be null");
267269

268-
return template.doCreateMono(connection -> connection.keyCommands().del(rawKey(key))).map(l -> l != 0);
270+
return template.doCreateMono(connection -> connection.keyCommands().del(rawKey(key))).map(count -> count != 0);
269271
}
270272

271273
@Override
@@ -274,10 +276,11 @@ public Flux<GeoResult<GeoLocation<V>>> search(K key, GeoReference<V> reference,
274276

275277
Assert.notNull(key, "Key must not be null");
276278
Assert.notNull(reference, "GeoReference must not be null");
279+
277280
GeoReference<ByteBuffer> rawReference = getGeoReference(reference);
278281

279-
return createFlux(geoCommands -> geoCommands
280-
.geoSearch(rawKey(key), rawReference, geoPredicate, args).map(this::readGeoResult));
282+
return createFlux(geoCommands -> geoCommands.geoSearch(rawKey(key), rawReference, geoPredicate, args)
283+
.map(this::readGeoResult));
281284
}
282285

283286
@Override
@@ -286,6 +289,7 @@ public Mono<Long> searchAndStore(K key, K destKey, GeoReference<V> reference,
286289

287290
Assert.notNull(key, "Key must not be null");
288291
Assert.notNull(reference, "GeoReference must not be null");
292+
289293
GeoReference<ByteBuffer> rawReference = getGeoReference(reference);
290294

291295
return createMono(geoCommands -> geoCommands.geoSearchStore(rawKey(destKey), rawKey(key),

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*
3939
* @author Mark Paluch
4040
* @author Christoph Strobl
41+
* @author John Blum
4142
* @since 2.0
4243
*/
4344
class DefaultReactiveHashOperations<H, HK, HV> implements ReactiveHashOperations<H, HK, HV> {
@@ -62,7 +63,8 @@ public Mono<Long> remove(H key, Object... hashKeys) {
6263
Assert.noNullElements(hashKeys, "Hash keys must not contain null elements");
6364

6465
return createMono(hashCommands -> Flux.fromArray(hashKeys) //
65-
.map(o -> (HK) o).map(this::rawHashKey) //
66+
.map(hashKey -> (HK) hashKey)
67+
.map(this::rawHashKey) //
6668
.collectList() //
6769
.flatMap(hks -> hashCommands.hDel(rawKey(key), hks)));
6870
}
@@ -84,8 +86,8 @@ public Mono<HV> get(H key, Object hashKey) {
8486
Assert.notNull(key, "Key must not be null");
8587
Assert.notNull(hashKey, "Hash key must not be null");
8688

87-
return createMono(hashCommands ->
88-
hashCommands.hGet(rawKey(key), rawHashKey((HK) hashKey)).map(this::readHashValue));
89+
return createMono(hashCommands -> hashCommands.hGet(rawKey(key), rawHashKey((HK) hashKey))
90+
.map(this::readHashValue));
8991
}
9092

9193
@Override
@@ -107,8 +109,7 @@ public Mono<Long> increment(H key, HK hashKey, long delta) {
107109
Assert.notNull(key, "Key must not be null");
108110
Assert.notNull(hashKey, "Hash key must not be null");
109111

110-
return template.doCreateMono(connection -> connection //
111-
.numberCommands() //
112+
return template.doCreateMono(connection -> connection.numberCommands()
112113
.hIncrBy(rawKey(key), rawHashKey(hashKey), delta));
113114
}
114115

@@ -118,8 +119,7 @@ public Mono<Double> increment(H key, HK hashKey, double delta) {
118119
Assert.notNull(key, "Key must not be null");
119120
Assert.notNull(hashKey, "Hash key must not be null");
120121

121-
return template.doCreateMono(connection -> connection //
122-
.numberCommands() //
122+
return template.doCreateMono(connection -> connection.numberCommands()
123123
.hIncrBy(rawKey(key), rawHashKey(hashKey), delta));
124124
}
125125

@@ -128,34 +128,35 @@ public Mono<HK> randomKey(H key) {
128128

129129
Assert.notNull(key, "Key must not be null");
130130

131-
return template.doCreateMono(connection -> connection //
132-
.hashCommands().hRandField(rawKey(key))).map(this::readRequiredHashKey);
131+
return template.doCreateMono(connection -> connection.hashCommands().hRandField(rawKey(key)))
132+
.map(this::readRequiredHashKey);
133133
}
134134

135135
@Override
136136
public Mono<Map.Entry<HK, HV>> randomEntry(H key) {
137137

138138
Assert.notNull(key, "Key must not be null");
139139

140-
return createMono(hashCommands ->hashCommands.hRandFieldWithValues(rawKey(key))).map(this::deserializeHashEntry);
140+
return createMono(hashCommands -> hashCommands.hRandFieldWithValues(rawKey(key)))
141+
.map(this::deserializeHashEntry);
141142
}
142143

143144
@Override
144145
public Flux<HK> randomKeys(H key, long count) {
145146

146147
Assert.notNull(key, "Key must not be null");
147148

148-
return template.doCreateFlux(connection -> connection //
149-
.hashCommands().hRandField(rawKey(key), count)).map(this::readRequiredHashKey);
149+
return template.doCreateFlux(connection -> connection.hashCommands().hRandField(rawKey(key), count))
150+
.map(this::readRequiredHashKey);
150151
}
151152

152153
@Override
153154
public Flux<Map.Entry<HK, HV>> randomEntries(H key, long count) {
154155

155156
Assert.notNull(key, "Key must not be null");
156157

157-
return template.doCreateFlux(connection -> connection //
158-
.hashCommands().hRandFieldWithValues(rawKey(key), count)).map(this::deserializeHashEntry);
158+
return template.doCreateFlux(connection -> connection.hashCommands().hRandFieldWithValues(rawKey(key), count))
159+
.map(this::deserializeHashEntry);
159160
}
160161

161162
@Override
@@ -211,7 +212,7 @@ public Flux<HV> values(H key) {
211212

212213
Assert.notNull(key, "Key must not be null");
213214

214-
return createFlux(connection -> connection.hVals(rawKey(key)) //
215+
return createFlux(hashCommands -> hashCommands.hVals(rawKey(key)) //
215216
.map(this::readRequiredHashValue));
216217
}
217218

@@ -278,28 +279,28 @@ private HK readRequiredHashKey(ByteBuffer buffer) {
278279

279280
HK hashKey = readHashKey(buffer);
280281

281-
if (hashKey == null) {
282-
throw new InvalidDataAccessApiUsageException("Deserialized hash key is null");
282+
if (hashKey != null) {
283+
return hashKey;
283284
}
284285

285-
return hashKey;
286+
throw new InvalidDataAccessApiUsageException("Deserialized hash key is null");
286287
}
287288

288289
@SuppressWarnings("unchecked")
289290
@Nullable
290291
private HV readHashValue(@Nullable ByteBuffer value) {
291-
return (HV) (value == null ? null : serializationContext.getHashValueSerializationPair().read(value));
292+
return value != null ? (HV) serializationContext.getHashValueSerializationPair().read(value) : null;
292293
}
293294

294295
private HV readRequiredHashValue(ByteBuffer buffer) {
295296

296297
HV hashValue = readHashValue(buffer);
297298

298-
if (hashValue == null) {
299-
throw new InvalidDataAccessApiUsageException("Deserialized hash value is null");
299+
if (hashValue != null) {
300+
return hashValue;
300301
}
301302

302-
return hashValue;
303+
throw new InvalidDataAccessApiUsageException("Deserialized hash value is null");
303304
}
304305

305306
private Map.Entry<HK, HV> deserializeHashEntry(Map.Entry<ByteBuffer, ByteBuffer> source) {
@@ -309,9 +310,11 @@ private Map.Entry<HK, HV> deserializeHashEntry(Map.Entry<ByteBuffer, ByteBuffer>
309310
private List<HV> deserializeHashValues(List<ByteBuffer> source) {
310311

311312
List<HV> values = new ArrayList<>(source.size());
313+
312314
for (ByteBuffer byteBuffer : source) {
313315
values.add(readHashValue(byteBuffer));
314316
}
317+
315318
return values;
316319
}
317320
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,12 @@ private V readValue(ByteBuffer buffer) {
351351

352352
private V readRequiredValue(ByteBuffer buffer) {
353353

354-
V v = readValue(buffer);
354+
V value = readValue(buffer);
355355

356-
if (v == null) {
357-
throw new InvalidDataAccessApiUsageException("Deserialized list value is null");
356+
if (value != null) {
357+
return value;
358358
}
359359

360-
return v;
360+
throw new InvalidDataAccessApiUsageException("Deserialized list value is null");
361361
}
362362
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* @author Mark Paluch
4141
* @author Christoph Strobl
4242
* @author Roman Bezpalko
43+
* @author John Blum
4344
* @since 2.0
4445
*/
4546
class DefaultReactiveSetOperations<K, V> implements ReactiveSetOperations<K, V> {
@@ -424,12 +425,12 @@ private V readValue(ByteBuffer buffer) {
424425

425426
private V readRequiredValue(ByteBuffer buffer) {
426427

427-
V v = readValue(buffer);
428+
V value = readValue(buffer);
428429

429-
if (v == null) {
430-
throw new InvalidDataAccessApiUsageException("Deserialized set value is null");
430+
if (value != null) {
431+
return value;
431432
}
432433

433-
return v;
434+
throw new InvalidDataAccessApiUsageException("Deserialized set value is null");
434435
}
435436
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @author Mark Paluch
4545
* @author Christoph Strobl
4646
* @author Jiahe Cai
47+
* @author John Blum
4748
* @since 2.0
4849
*/
4950
class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K, V> {
@@ -336,13 +337,13 @@ private V readValue(ByteBuffer buffer) {
336337

337338
private V readRequiredValue(ByteBuffer buffer) {
338339

339-
V v = readValue(buffer);
340+
V value = readValue(buffer);
340341

341-
if (v == null) {
342-
throw new InvalidDataAccessApiUsageException("Deserialized value is null");
342+
if (value != null) {
343+
return value;
343344
}
344345

345-
return v;
346+
throw new InvalidDataAccessApiUsageException("Deserialized value is null");
346347
}
347348

348349
private SerializationPair<String> stringSerializationPair() {
@@ -372,5 +373,4 @@ private List<V> deserializeValues(List<ByteBuffer> source) {
372373

373374
return result;
374375
}
375-
376376
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
3939
import org.springframework.data.redis.serializer.RedisSerializationContext;
4040
import org.springframework.data.redis.util.ByteUtils;
41+
import org.springframework.data.redis.util.RedisAssertions;
4142
import org.springframework.lang.Nullable;
4243
import org.springframework.util.Assert;
4344

@@ -744,13 +745,8 @@ private V readValue(ByteBuffer buffer) {
744745

745746
private V readRequiredValue(ByteBuffer buffer) {
746747

747-
V v = readValue(buffer);
748-
749-
if (v == null) {
750-
throw new InvalidDataAccessApiUsageException("Deserialized sorted set value is null");
751-
}
752-
753-
return v;
748+
return RedisAssertions.requireNonNull(readValue(buffer),
749+
() -> new InvalidDataAccessApiUsageException("Deserialized sorted set value is null"));
754750
}
755751

756752
private TypedTuple<V> readTypedTuple(Tuple raw) {

0 commit comments

Comments
 (0)