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

org.springframework.data.redis.core.ReactiveHashOperationsExtensions.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.awaitFirstOrNull
import kotlinx.coroutines.reactive.awaitSingle

/**
 * Coroutines variant of [ReactiveHashOperations.hasKey].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.hasKeyAndAwait(key: H, hashKey: HK): Boolean =
		hasKey(key, hashKey).awaitSingle()

/**
 * Coroutines variant of [ReactiveHashOperations.get].
 *
 * @author Mark Paluch
 * @author Christoph Strobl
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.getAndAwait(key: H, hashKey: HK): HV? =
		get(key, hashKey).awaitFirstOrNull()

/**
 * Coroutines variant of [ReactiveHashOperations.multiGet].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.multiGetAndAwait(key: H, vararg hashKeys: HK): List =
		multiGet(key, hashKeys.toCollection(ArrayList())).awaitSingle()

/**
 * Coroutines variant of [ReactiveHashOperations.increment].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.incrementAndAwait(key: H, hashKey: HK, delta: Long): Long =
		increment(key, hashKey, delta).awaitSingle()

/**
 * Coroutines variant of [ReactiveHashOperations.keys].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveHashOperations.keysAsFlow(key: H): Flow =
		keys(key).asFlow()

/**
 * Coroutines variant of [ReactiveHashOperations.increment].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.incrementAndAwait(key: H, hashKey: HK, delta: Double): Double =
		increment(key, hashKey, delta).awaitSingle()

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

/**
 * Coroutines variant of [ReactiveHashOperations.putAll].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.putAllAndAwait(key: H, map: Map): Boolean =
		putAll(key, map).awaitSingle()

/**
 * Coroutines variant of [ReactiveHashOperations.put].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.putAndAwait(key: H, hashKey: HK, hashValue: HV): Boolean =
		put(key, hashKey, hashValue).awaitSingle()

/**
 * Coroutines variant of [ReactiveHashOperations.putIfAbsent].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.putIfAbsentAndAwait(key: H, hashKey: HK, hashValue: HV): Boolean =
		putIfAbsent(key, hashKey, hashValue).awaitSingle()

/**
 * Coroutines variant of [ReactiveHashOperations.values].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveHashOperations.valuesAsFlow(key: H): Flow =
		values(key).asFlow()

/**
 * Coroutines variant of [ReactiveHashOperations.entries].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveHashOperations.entriesAsFlow(key: H): Flow> =
		entries(key).asFlow()

/**
 * Coroutines variant of [ReactiveHashOperations.scan].
 *
 * @author Sebastien Deleuze
 * @since 2.2
 */
fun  ReactiveHashOperations.scanAsFlow(key: H, options: ScanOptions = ScanOptions.NONE): Flow> =
		scan(key, options).asFlow()

/**
 * Coroutines variant of [ReactiveHashOperations.remove].
 *
 * @author Mark Paluch
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.removeAndAwait(key: H, vararg hashKeys: Any): Long =
		remove(key, *hashKeys).awaitSingle()

/**
 * Coroutines variant of [ReactiveListOperations.delete].
 *
 * @author Christoph Strobl
 * @since 2.2
 */
suspend fun  ReactiveHashOperations.deleteAndAwait(key: H): Boolean =
		delete(key).awaitSingle()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy