All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.springframework.data.redis.core.ReactiveSetOperationsExtensions.kt Maven / Gradle / Ivy
/*
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.core
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.reactive.asFlow
import kotlinx.coroutines.reactive.awaitFirstOrNull
import kotlinx.coroutines.reactive.awaitSingle
/**
* Coroutines variant of [ReactiveSetOperations.add].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.addAndAwait(key: K, vararg values: V): Long =
add(key, *values).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.remove].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.removeAndAwait(key: K, vararg values: V): Long =
remove(key, *values).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.pop].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.popAndAwait(key: K): V? =
pop(key).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveSetOperations.pop].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.popAsFlow(key: K, count: Long): Flow =
pop(key, count).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.move].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.moveAndAwait(sourceKey: K, value: V, destKey: K): Boolean =
move(sourceKey, value, destKey).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.size].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.sizeAndAwait(key: K): Long =
size(key).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.isMember].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.isMemberAndAwait(key: K, value: V): Boolean =
isMember(key, value).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.intersect].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.intersectAsFlow(key: K, otherKey: K): Flow =
intersect(key, otherKey).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.intersect].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.intersectAsFlow(key: K, otherKeys: Collection): Flow =
intersect(key, otherKeys).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.intersect].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.intersectAsFlow(otherKeys: Collection): Flow =
intersect(otherKeys).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.intersectAndStore].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.intersectAndStoreAndAwait(key: K, otherKey: K, destKey: K): Long =
intersectAndStore(key, otherKey, destKey).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.intersectAndStore].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.intersectAndStoreAndAwait(keys: Collection, destKey: K): Long =
intersectAndStore(keys, destKey).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.union].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.unionAsFlow(key: K, otherKey: K): Flow =
union(key, otherKey).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.union].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.unionAsFlow(key: K, otherKeys: Collection): Flow =
union(key, otherKeys).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.union].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.unionAsFlow(otherKeys: Collection): Flow =
union(otherKeys).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.unionAndStore].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.unionAndStoreAndAwait(key: K, otherKey: K, destKey: K): Long =
unionAndStore(key, otherKey, destKey).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.unionAndStore].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.unionAndStoreAndAwait(keys: Collection, destKey: K): Long =
unionAndStore(keys, destKey).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.difference].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.differenceAsFlow(key: K, otherKey: K): Flow =
difference(key, otherKey).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.difference].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.differenceAsFlow(key: K, otherKeys: Collection): Flow =
difference(key, otherKeys).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.difference].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.differenceAsFlow(otherKeys: Collection): Flow =
difference(otherKeys).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.differenceAndStore].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.differenceAndStoreAndAwait(key: K, otherKey: K, destKey: K): Long =
differenceAndStore(key, otherKey, destKey).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.differenceAndStore].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.differenceAndStoreAndAwait(keys: Collection, destKey: K): Long =
differenceAndStore(keys, destKey).awaitSingle()
/**
* Coroutines variant of [ReactiveSetOperations.members].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.membersAsFlow(key: K): Flow =
members(key).asFlow()
/**
* Coroutines variant of [ReactiveHashOperations.scan].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.scanAsFlow(key: K, options: ScanOptions = ScanOptions.NONE): Flow =
scan(key, options).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.randomMember].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.randomMemberAndAwait(key: K): V? =
randomMember(key).awaitFirstOrNull()
/**
* Coroutines variant of [ReactiveSetOperations.distinctRandomMembers].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.distinctRandomMembersAsFlow(key: K, count: Long): Flow =
distinctRandomMembers(key, count).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.randomMembers].
*
* @author Sebastien Deleuze
* @since 2.2
*/
fun ReactiveSetOperations.randomMembersAsFlow(key: K, count: Long): Flow =
randomMembers(key, count).asFlow()
/**
* Coroutines variant of [ReactiveSetOperations.delete].
*
* @author Mark Paluch
* @since 2.2
*/
suspend fun ReactiveSetOperations.deleteAndAwait(key: K): Boolean =
delete(key).awaitSingle()