Skip to content

Commit 9e473b5

Browse files
committed
Polishing.
Reorder methods to align with ListOperations. Simplify tests to avoid test noise. See #2692 Original pull request: #2704
1 parent 157f5e4 commit 9e473b5

File tree

4 files changed

+65
-83
lines changed

4 files changed

+65
-83
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ public Mono<V> leftPop(K key) {
240240

241241
}
242242

243+
@Override
244+
public Flux<V> leftPop(K key, long count) {
245+
246+
Assert.notNull(key, "Key must not be null");
247+
248+
return createFlux(listCommands -> listCommands.lPop(rawKey(key), count).map(this::readValue));
249+
}
250+
243251
@Override
244252
public Mono<V> leftPop(K key, Duration timeout) {
245253

@@ -253,19 +261,19 @@ public Mono<V> leftPop(K key, Duration timeout) {
253261
}
254262

255263
@Override
256-
public Flux<V> leftPop(K key, long count) {
264+
public Mono<V> rightPop(K key) {
257265

258266
Assert.notNull(key, "Key must not be null");
259267

260-
return createFlux(listCommands -> listCommands.lPop(rawKey(key), count).map(this::readValue));
268+
return createMono(listCommands -> listCommands.rPop(rawKey(key)).map(this::readValue));
261269
}
262270

263271
@Override
264-
public Mono<V> rightPop(K key) {
272+
public Flux<V> rightPop(K key, long count) {
265273

266274
Assert.notNull(key, "Key must not be null");
267275

268-
return createMono(listCommands -> listCommands.rPop(rawKey(key)).map(this::readValue));
276+
return createFlux(listCommands -> listCommands.rPop(rawKey(key), count).map(this::readValue));
269277
}
270278

271279
@Override
@@ -280,14 +288,6 @@ public Mono<V> rightPop(K key, Duration timeout) {
280288
.map(popResult -> readValue(popResult.getValue())));
281289
}
282290

283-
@Override
284-
public Flux<V> rightPop(K key, long count) {
285-
286-
Assert.notNull(key, "Key must not be null");
287-
288-
return createFlux(listCommands -> listCommands.rPop(rawKey(key), count).map(this::readValue));
289-
}
290-
291291
@Override
292292
public Mono<V> rightPopAndLeftPush(K sourceKey, K destinationKey) {
293293

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,17 @@ default Mono<V> move(MoveFrom<K> from, MoveTo<K> to, Duration timeout) {
313313
*/
314314
Mono<V> leftPop(K key);
315315

316+
/**
317+
* Removes {@link Long count} elements from the left-side of the Redis list stored at key.
318+
*
319+
* @param key must not be {@literal null}.
320+
* @param count {@link Long count} of the number of elements to remove from the left-side of the Redis list.
321+
* @return a {@link Flux} containing the elements removed from the Redis list.
322+
* @since 3.2
323+
* @see <a href="https://redis.io/commands/lpop">Redis Documentation: LPOP</a>
324+
*/
325+
Flux<V> leftPop(K key, long count);
326+
316327
/**
317328
* Removes and returns first element from lists stored at {@code key}. <br>
318329
* <b>Results return once an element available or {@code timeout} reached.</b>
@@ -327,23 +338,24 @@ default Mono<V> move(MoveFrom<K> from, MoveTo<K> to, Duration timeout) {
327338
Mono<V> leftPop(K key, Duration timeout);
328339

329340
/**
330-
* Removes {@link Long count} elements from the left-side of the Redis list stored at key.
341+
* Removes and returns last element in list stored at {@code key}.
331342
*
332-
* @param key {@link K Key} referring to the list stored in Redis; must not be {@literal null}.
333-
* @param count {@link Long count} of the number of elements to remove from the left-side of the Redis list.
334-
* @return a {@link Flux} containing the elements removed from the Redis list.
335-
* @since 3.2
343+
* @param key must not be {@literal null}.
344+
* @return
345+
* @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
336346
*/
337-
Flux<V> leftPop(K key, long count);
347+
Mono<V> rightPop(K key);
338348

339349
/**
340-
* Removes and returns last element in list stored at {@code key}.
350+
* Removes {@link Long count} elements from the right-side of the Redis list stored at key.
341351
*
342352
* @param key must not be {@literal null}.
343-
* @return
353+
* @param count {@link Long count} of the number of elements to remove from the right-side of the Redis list.
354+
* @return a {@link Flux} containing the elements removed from the Redis list.
355+
* @since 3.2
344356
* @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
345357
*/
346-
Mono<V> rightPop(K key);
358+
Flux<V> rightPop(K key, long count);
347359

348360
/**
349361
* Removes and returns last element from lists stored at {@code key}. <br>
@@ -358,16 +370,6 @@ default Mono<V> move(MoveFrom<K> from, MoveTo<K> to, Duration timeout) {
358370
*/
359371
Mono<V> rightPop(K key, Duration timeout);
360372

361-
/**
362-
* Removes {@link Long count} elements from the right-side of the Redis list stored at key.
363-
*
364-
* @param key {@link K Key} referring to the list stored in Redis; must not be {@literal null}.
365-
* @param count {@link Long count} of the number of elements to remove from the right-side of the Redis list.
366-
* @return a {@link Flux} containing the elements removed from the Redis list.
367-
* @since 3.2
368-
*/
369-
Flux<V> rightPop(K key, long count);
370-
371373
/**
372374
* Remove the last element from list at {@code sourceKey}, append it to {@code destinationKey} and return its value.
373375
*

src/main/kotlin/org/springframework/data/redis/core/ReactiveListOperationsExtensions.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -174,41 +174,32 @@ suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.indexAndAwait(key: K
174174
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.leftPopAndAwait(key: K): V? =
175175
leftPop(key).awaitFirstOrNull()
176176

177-
/**
178-
* Coroutines variant of [ReactiveListOperations.leftPop].
179-
*
180-
* @author Mark Paluch
181-
* @since 2.2
182-
*/
183-
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.leftPopAndAwait(key: K, timeout: Duration): V? =
184-
leftPop(key, timeout).awaitFirstOrNull()
185-
186177
/**
187178
* Coroutines variant of [ReactiveListOperations.leftPop] with count.
188179
*
189180
* @author John Blum
190181
* @since 3.2
191182
*/
192183
fun <K : Any, V : Any> ReactiveListOperations<K, V>.leftPopAsFlow(key: K, count :Long): Flow<V> =
193-
leftPop(key, count).asFlow()
184+
leftPop(key, count).asFlow()
194185

195186
/**
196-
* Coroutines variant of [ReactiveListOperations.rightPop].
187+
* Coroutines variant of [ReactiveListOperations.leftPop].
197188
*
198189
* @author Mark Paluch
199190
* @since 2.2
200191
*/
201-
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAndAwait(key: K): V? =
202-
rightPop(key).awaitFirstOrNull()
192+
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.leftPopAndAwait(key: K, timeout: Duration): V? =
193+
leftPop(key, timeout).awaitFirstOrNull()
203194

204195
/**
205196
* Coroutines variant of [ReactiveListOperations.rightPop].
206197
*
207198
* @author Mark Paluch
208199
* @since 2.2
209200
*/
210-
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAndAwait(key: K, timeout: Duration): V? =
211-
rightPop(key, timeout).awaitFirstOrNull()
201+
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAndAwait(key: K): V? =
202+
rightPop(key).awaitFirstOrNull()
212203

213204
/**
214205
* Coroutines variant of [ReactiveListOperations.rightPop] with count.
@@ -217,7 +208,16 @@ suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAndAwait(key
217208
* @since 3.2
218209
*/
219210
fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAsFlow(key: K, count:Long): Flow<V> =
220-
rightPop(key, count).asFlow()
211+
rightPop(key, count).asFlow()
212+
213+
/**
214+
* Coroutines variant of [ReactiveListOperations.rightPop].
215+
*
216+
* @author Mark Paluch
217+
* @since 2.2
218+
*/
219+
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAndAwait(key: K, timeout: Duration): V? =
220+
rightPop(key, timeout).awaitFirstOrNull()
221221

222222
/**
223223
* Coroutines variant of [ReactiveListOperations.rightPopAndLeftPush].

src/test/java/org/springframework/data/redis/core/DefaultReactiveListOperationsIntegrationTests.java

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void size() {
121121
@ParameterizedRedisTest // DATAREDIS-602
122122
void leftPush() {
123123

124-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
124+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
125125

126126
K key = keyFactory.instance();
127127
V value1 = valueFactory.instance();
@@ -147,7 +147,7 @@ void leftPush() {
147147
@ParameterizedRedisTest // DATAREDIS-602
148148
void leftPushAll() {
149149

150-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
150+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
151151

152152
K key = keyFactory.instance();
153153
V value1 = valueFactory.instance();
@@ -191,7 +191,7 @@ void leftPushIfPresent() {
191191
@ParameterizedRedisTest // DATAREDIS-602
192192
void leftPushWithPivot() {
193193

194-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
194+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
195195

196196
K key = keyFactory.instance();
197197
V value1 = valueFactory.instance();
@@ -219,7 +219,7 @@ void leftPushWithPivot() {
219219
@ParameterizedRedisTest // DATAREDIS-602
220220
void rightPush() {
221221

222-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
222+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
223223

224224
K key = keyFactory.instance();
225225
V value1 = valueFactory.instance();
@@ -244,7 +244,7 @@ void rightPush() {
244244
@ParameterizedRedisTest // DATAREDIS-602
245245
void rightPushAll() {
246246

247-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
247+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
248248

249249
K key = keyFactory.instance();
250250
V value1 = valueFactory.instance();
@@ -274,7 +274,7 @@ void rightPushIfPresent() {
274274
@ParameterizedRedisTest // DATAREDIS-602
275275
void rightPushWithPivot() {
276276

277-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
277+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
278278

279279
K key = keyFactory.instance();
280280
V value1 = valueFactory.instance();
@@ -364,7 +364,7 @@ void moveWithTimeout() {
364364
@ParameterizedRedisTest // DATAREDIS-602
365365
void set() {
366366

367-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
367+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
368368

369369
K key = keyFactory.instance();
370370
V value1 = valueFactory.instance();
@@ -384,7 +384,7 @@ void set() {
384384
@ParameterizedRedisTest // DATAREDIS-602
385385
void remove() {
386386

387-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
387+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
388388

389389
K key = keyFactory.instance();
390390
V value1 = valueFactory.instance();
@@ -406,7 +406,7 @@ void remove() {
406406
@ParameterizedRedisTest // DATAREDIS-602
407407
void index() {
408408

409-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
409+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
410410

411411
K key = keyFactory.instance();
412412
V value1 = valueFactory.instance();
@@ -448,7 +448,7 @@ void lastIndexOf() {
448448
@ParameterizedRedisTest // DATAREDIS-602
449449
void leftPop() {
450450

451-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
451+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
452452

453453
K key = keyFactory.instance();
454454
V value1 = valueFactory.instance();
@@ -459,20 +459,10 @@ void leftPop() {
459459
listOperations.leftPop(key).as(StepVerifier::create).expectNext(value2).verifyComplete();
460460
}
461461

462-
@ParameterizedRedisTest // GH-2692
463-
@SuppressWarnings("all")
464-
void leftPopWithNullKey() {
465-
466-
assertThatIllegalArgumentException()
467-
.isThrownBy(() -> this.listOperations.leftPop(null, 100L))
468-
.withMessage("Key must not be null")
469-
.withNoCause();
470-
}
471-
472462
@ParameterizedRedisTest // GH-2692
473463
void leftPopWithCount() {
474464

475-
assumeThat(this.valueFactory).isInstanceOf(ByteBufferObjectFactory.class);
465+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
476466

477467
K key = keyFactory.instance();
478468
V value1 = valueFactory.instance();
@@ -494,7 +484,7 @@ void leftPopWithCount() {
494484
@ParameterizedRedisTest // DATAREDIS-602
495485
void rightPop() {
496486

497-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
487+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
498488

499489
K key = keyFactory.instance();
500490
V value1 = valueFactory.instance();
@@ -505,16 +495,6 @@ void rightPop() {
505495
listOperations.rightPop(key).as(StepVerifier::create).expectNext(value2).verifyComplete();
506496
}
507497

508-
@ParameterizedRedisTest // GH-2692
509-
@SuppressWarnings("all")
510-
void rightPopWithNullKey() {
511-
512-
assertThatIllegalArgumentException()
513-
.isThrownBy(() -> this.listOperations.rightPop(null, 100L))
514-
.withMessage("Key must not be null")
515-
.withNoCause();
516-
}
517-
518498
@ParameterizedRedisTest // GH-2692
519499
void rightPopWithCount() {
520500

@@ -540,7 +520,7 @@ void rightPopWithCount() {
540520
@ParameterizedRedisTest // DATAREDIS-602
541521
void leftPopWithTimeout() {
542522

543-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
523+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
544524

545525
K key = keyFactory.instance();
546526
V value1 = valueFactory.instance();
@@ -562,7 +542,7 @@ void leftPopWithMillisecondTimeoutShouldFail() {
562542
@ParameterizedRedisTest // DATAREDIS-602
563543
void rightPopWithTimeout() {
564544

565-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
545+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
566546

567547
K key = keyFactory.instance();
568548
V value1 = valueFactory.instance();
@@ -576,7 +556,7 @@ void rightPopWithTimeout() {
576556
@ParameterizedRedisTest // DATAREDIS-602
577557
void rightPopAndLeftPush() {
578558

579-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
559+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
580560

581561
K source = keyFactory.instance();
582562
K target = keyFactory.instance();
@@ -594,7 +574,7 @@ void rightPopAndLeftPush() {
594574
@EnabledIfLongRunningTest
595575
void rightPopAndLeftPushWithTimeout() {
596576

597-
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
577+
assumeThat(this.valueFactory).isNotInstanceOf(ByteBufferObjectFactory.class);
598578

599579
K source = keyFactory.instance();
600580
K target = keyFactory.instance();

0 commit comments

Comments
 (0)