DATAREDIS-1111 - Add missing list and zset coroutine extensions.

Original Pull Request: #514
This commit is contained in:
wonwoo
2020-03-01 13:44:31 +09:00
committed by Christoph Strobl
parent df720bde8f
commit 62042a5d6d
4 changed files with 135 additions and 0 deletions

View File

@@ -201,6 +201,24 @@ suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAndAwait(key
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAndAwait(key: K, timeout: Duration): V? =
rightPop(key, timeout).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveListOperations.rightPopAndLeftPush].
*
* @author Wonwoo Lee
* @since 2.3
*/
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAndLeftPushAndAwait(key: K, destinationKey: K): V? =
rightPopAndLeftPush(key, destinationKey).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveListOperations.rightPopAndLeftPush].
*
* @author Wonwoo Lee
* @since 2.3
*/
suspend fun <K : Any, V : Any> ReactiveListOperations<K, V>.rightPopAndLeftPushAndAwait(key: K, destinationKey: K, timeout: Duration): V? =
rightPopAndLeftPush(key, destinationKey, timeout).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveListOperations.delete].
*

View File

@@ -159,6 +159,15 @@ fun <K : Any, V : Any> ReactiveZSetOperations<K, V>.reverseRangeByScoreWithScore
suspend fun <K : Any, V : Any> ReactiveZSetOperations<K, V>.countAndAwait(key: K, range: Range<Double>): Long =
count(key, range).awaitSingle()
/**
* Coroutines variant of [ReactiveZSetOperations.size].
*
* @author Wonwoo Lee
* @since 2.3
*/
suspend fun <K : Any, V : Any> ReactiveZSetOperations<K, V>.sizeAndAwait(key: K): Long =
size(key).awaitSingle()
/**
* Coroutines variant of [ReactiveZSetOperations.score].
*
@@ -258,6 +267,24 @@ suspend fun <K : Any, V : Any> ReactiveZSetOperations<K, V>.intersectAndStoreAnd
suspend fun <K : Any, V : Any> ReactiveZSetOperations<K, V>.intersectAndStoreAndAwait(key: K, otherKeys: Collection<K>, destKey: K, aggregate: RedisZSetCommands.Aggregate, weights: RedisZSetCommands.Weights): Long =
intersectAndStore(key, otherKeys, destKey, aggregate, weights).awaitSingle()
/**
* Coroutines variant of [ReactiveZSetOperations.rangeByLex].
*
* @author Wonwoo Lee
* @since 2.3
*/
fun <K : Any, V : Any> ReactiveZSetOperations<K, V>.rangeByLexAndAwait(key: K, range: Range<String>, limit: Limit? = null): Flow<V> =
(if (limit == null) rangeByLex(key, range) else rangeByLex(key, range, limit)).asFlow()
/**
* Coroutines variant of [ReactiveZSetOperations.reverseRangeByLex].
*
* @author Wonwoo Lee
* @since 2.3
*/
fun <K : Any, V : Any> ReactiveZSetOperations<K, V>.reverseRangeByLexAndAwait(key: K, range: Range<String>, limit: Limit? = null): Flow<V> =
(if (limit == null) reverseRangeByLex(key, range) else reverseRangeByLex(key, range, limit)).asFlow()
/**
* Coroutines variant of [ReactiveZSetOperations.delete].
*

View File

@@ -334,6 +334,36 @@ class ReactiveListOperationsExtensionsUnitTests {
}
}
@Test
fun rightPopAndLeftPush() {
val operations = mockk<ReactiveListOperations<String, String>>()
every { operations.rightPopAndLeftPush(any(), any()) } returns Mono.just("foo")
runBlocking {
assertThat(operations.rightPopAndLeftPushAndAwait("foo", "bar")).isEqualTo("foo")
}
verify {
operations.rightPopAndLeftPush("foo", "bar")
}
}
@Test
fun blockingRightPopAndLeftPush() {
val operations = mockk<ReactiveListOperations<String, String>>()
every { operations.rightPopAndLeftPush(any(), any(), Duration.ofDays(1)) } returns Mono.just("foo")
runBlocking {
assertThat(operations.rightPopAndLeftPushAndAwait("foo", "bar", Duration.ofDays(1))).isEqualTo("foo")
}
verify {
operations.rightPopAndLeftPush("foo", "bar", Duration.ofDays(1))
}
}
@Test // DATAREDIS-937
fun delete() {

View File

@@ -304,6 +304,21 @@ class ReactiveZSetOperationsExtensionsUnitTests {
}
}
@Test
fun size() {
val operations = mockk<ReactiveZSetOperations<String, String>>()
every { operations.size(any()) } returns Mono.just(1)
runBlocking {
assertThat(operations.sizeAndAwait("foo")).isEqualTo(1)
}
verify {
operations.size("foo")
}
}
@Test // DATAREDIS-937
fun score() {
@@ -483,4 +498,49 @@ class ReactiveZSetOperationsExtensionsUnitTests {
operations.intersectAndStore("foo", listOf("bar"), "baz", Aggregate.MAX, Weights.fromSetCount(1))
}
}
@Test
fun rangeByLex() {
val operations = mockk<ReactiveZSetOperations<String, String>>()
every { operations.rangeByLex(any(), any()) } returns Flux.just("bar")
runBlocking {
assertThat(operations.rangeByLexAndAwait("foo", Range.just("bar")).toList()).contains("bar")
}
verify {
operations.rangeByLex("foo", Range.just("bar"))
}
}
@Test
fun reverseRangeByLexAndAwait() {
val operations = mockk<ReactiveZSetOperations<String, String>>()
every { operations.reverseRangeByLex(any(), any()) } returns Flux.just("bar")
runBlocking {
assertThat(operations.reverseRangeByLexAndAwait("foo", Range.just("bar")).toList()).contains("bar")
}
verify {
operations.reverseRangeByLex("foo", Range.just("bar"))
}
}
@Test
fun delete() {
val operations = mockk<ReactiveZSetOperations<String, String>>()
every { operations.delete(any()) } returns Mono.just(true)
runBlocking {
assertThat(operations.deleteAndAwait("foo")).isTrue()
}
verify {
operations.delete("foo")
}
}
}