All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.data.redis.core.ReactiveStreamOperationsExtensions.kt Maven / Gradle / Ivy

There is a newer version: 3.2.3_1
Show newest version
/*
 * Copyright 2019 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.asPublisher
import kotlinx.coroutines.reactive.awaitSingle
import org.springframework.data.domain.Range
import org.springframework.data.redis.connection.RedisZSetCommands.*
import org.springframework.data.redis.connection.stream.*

/**
 * Coroutines variant of [ReactiveStreamOperations.acknowledge].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.acknowledgeAndAwait(key: K, group: String, vararg recordIds: String): Long =
		acknowledge(key, group, *recordIds).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.acknowledge].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.acknowledgeAndAwait(key: K, group: String, vararg recordIds: RecordId): Long =
		acknowledge(key, group, *recordIds).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.acknowledge].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.acknowledgeAndAwait(group: String, record: Record): Long =
		acknowledge(group, record).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.add].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveStreamOperations.add(key: K, bodyFlow: Flow>): Flow =
		add(key, bodyFlow.asPublisher()).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.add].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.addAndAwait(record: MapRecord): RecordId =
		add(record).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.add].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.addAndAwait(record: Record): RecordId =
		add(record).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.delete].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.deleteAndAwait(key: K, vararg recordIds: String): Long =
		delete(key, *recordIds).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.delete].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.deleteAndAwait(record: Record): Long =
		delete(record).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.delete].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.deleteAndAwait(key: K, vararg recordIds: RecordId): Long =
		delete(key, *recordIds).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.createGroup].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.createGroupAndAwait(key: K, group: String): String =
		createGroup(key, group).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.createGroup].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.createGroupAndAwait(key: K, readOffset: ReadOffset, group: String): String =
		createGroup(key, readOffset, group).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.deleteConsumer].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.deleteConsumerAndAwait(key: K, consumer: Consumer): String =
		deleteConsumer(key, consumer).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.destroyGroup].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.destroyGroupAndAwait(key: K, group: String): String =
		destroyGroup(key, group).awaitSingle()

/**
 * Coroutines variant of [ReactiveStreamOperations.size].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.sizeAndAwait(key: K): Long =
		size(key).awaitSingle()


/**
 * Coroutines variant of [ReactiveStreamOperations.range].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveStreamOperations.rangeAsFlow(key: K, range: Range, limit: Limit = Limit.unlimited()): Flow>
		= range(key, range, limit).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.range].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
inline fun  ReactiveStreamOperations.rangeWithTypeAsFlow(key: K, range: Range, limit: Limit = Limit.unlimited()): Flow>
		= range(V::class.java, key, range, limit).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.read].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveStreamOperations.readAsFlow(vararg stream: StreamOffset): Flow> =
		read(*stream).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.read].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveStreamOperations.readAsFlow(readOptions: StreamReadOptions, vararg stream: StreamOffset): Flow> =
		read(readOptions, *stream).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.read].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
inline fun  ReactiveStreamOperations.readWithTypeAsFlow(vararg stream: StreamOffset): Flow> =
		read(V::class.java, *stream).asFlow()


/**
 * Coroutines variant of [ReactiveStreamOperations.read].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
inline fun  ReactiveStreamOperations.readWithTypeAsFlow(readOptions: StreamReadOptions, vararg stream: StreamOffset): Flow> =
		read(V::class.java, readOptions, *stream).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.read].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveStreamOperations.readAsFlow(consumer: Consumer, vararg stream: StreamOffset): Flow> =
		read(consumer, *stream).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.read].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveStreamOperations.readAsFlow(consumer: Consumer, readOptions: StreamReadOptions, vararg stream: StreamOffset): Flow> =
		read(consumer, readOptions, *stream).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.read].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
inline fun  ReactiveStreamOperations.readWithTypeAsFlow(consumer: Consumer, vararg stream: StreamOffset): Flow> =
		read(V::class.java, consumer, *stream).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.read].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
inline fun  ReactiveStreamOperations.readWithTypeAsFlow(consumer: Consumer, readOptions: StreamReadOptions, vararg stream: StreamOffset): Flow> =
		read(V::class.java, consumer, readOptions, *stream).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.reverseRange].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveStreamOperations.reverseRangeAsFlow(key: K, range: Range, limit: Limit = Limit.unlimited()): Flow>
		= reverseRange(key, range, limit).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.reverseRange].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
inline fun  ReactiveStreamOperations.reverseRangeWithTypeAsFlow(key: K, range: Range, limit: Limit = Limit.unlimited()): Flow> =
		reverseRange(V::class.java, key, range, limit).asFlow()

/**
 * Coroutines variant of [ReactiveStreamOperations.trim].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveStreamOperations.trimAndAwait(key: K, count: Long): Long =
		trim(key, count).awaitSingle()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy