Skip to content

Commit a0bcf01

Browse files
committed
Polishing.
Unroll extension to avoid JvmOverload usage. Closes #2227
1 parent da816c1 commit a0bcf01

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

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

+26-8
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,34 @@ fun <K : Any, HK : Any, HV : Any> ReactiveStreamOperations<K, HK, HV>.reverseRan
256256
* @author Sebastien Deleuze
257257
* @since 2.2
258258
*/
259-
inline fun <K : Any, reified V : Any> ReactiveStreamOperations<K, *, *>.reverseRangeWithTypeAsFlow(key: K, range: Range<String>, limit: Limit = Limit.unlimited()): Flow<ObjectRecord<K, V>> =
260-
reverseRange(V::class.java, key, range, limit).asFlow()
259+
inline fun <K : Any, reified V : Any> ReactiveStreamOperations<K, *, *>.reverseRangeWithTypeAsFlow(
260+
key: K,
261+
range: Range<String>,
262+
limit: Limit = Limit.unlimited()
263+
): Flow<ObjectRecord<K, V>> =
264+
reverseRange(V::class.java, key, range, limit).asFlow()
261265

262266
/**
263267
* Coroutines variant of [ReactiveStreamOperations.trim].
264268
*
265-
* @author Mark Paluch
266-
* @author Quantum64@github
267-
* @since 2.2
269+
* @author Quantum64
270+
* @since 2.7.4
271+
*/
272+
suspend fun <K : Any, HK : Any, HV : Any> ReactiveStreamOperations<K, HK, HV>.trimAndAwait(
273+
key: K,
274+
count: Long
275+
): Long =
276+
trim(key, count).awaitSingle()
277+
278+
/**
279+
* Coroutines variant of [ReactiveStreamOperations.trim].
280+
*
281+
* @author Quantum64
282+
* @since 2.7.4
268283
*/
269-
@JvmOverloads // Maintain compatibility with versions <= 2.6.0
270-
suspend fun <K : Any, HK : Any, HV : Any> ReactiveStreamOperations<K, HK, HV>.trimAndAwait(key: K, count: Long, approximateTrimming: Boolean = false): Long =
271-
trim(key, count, approximateTrimming).awaitSingle()
284+
suspend fun <K : Any, HK : Any, HV : Any> ReactiveStreamOperations<K, HK, HV>.trimAndAwait(
285+
key: K,
286+
count: Long,
287+
approximateTrimming: Boolean
288+
): Long =
289+
trim(key, count, approximateTrimming).awaitSingle()

src/test/kotlin/org/springframework/data/redis/core/ReactiveStreamOperationsExtensionsUnitTests.kt

+15
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,19 @@ class ReactiveStreamOperationsExtensionsUnitTests {
492492
operations.trim("foo", 1)
493493
}
494494
}
495+
496+
@Test // GH-2227
497+
fun trimApproximate() {
498+
499+
val operations = mockk<ReactiveStreamOperations<String, String, String>>()
500+
every { operations.trim(any(), any(), any()) } returns Mono.just(1)
501+
502+
runBlocking {
503+
assertThat(operations.trimAndAwait("foo", 1, true)).isEqualTo(1)
504+
}
505+
506+
verify {
507+
operations.trim("foo", 1, true)
508+
}
509+
}
495510
}

0 commit comments

Comments
 (0)