diff --git a/pom.xml b/pom.xml index 2eaf0b8218..3c164d6fc0 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 io.lettuce @@ -73,6 +74,8 @@ 3.0.6 1.0.3 1.7.25 + 1.4.0 + 1.3.9 UTF-8 @@ -84,8 +87,8 @@ scm:git:https://github.com/lettuce-io/lettuce-core.git scm:git:https://github.com/lettuce-io/lettuce-core.git http://github.com/lettuce-io/lettuce-core - HEAD - + HEAD + @@ -182,6 +185,27 @@ true + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + true + + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactive + ${kotlinx-coroutines.version} + true + + + + org.jetbrains.kotlinx + kotlinx-coroutines-jdk8 + ${kotlinx-coroutines.version} + true + + @@ -578,14 +602,48 @@ + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + -Xopt-in=kotlin.RequiresOptIn + -Xopt-in=io.lettuce.core.ExperimentalLettuceCoroutinesApi + + ${project.basedir}/src/main/kotlin + + + + compile + process-sources + + compile + + + + + test-compile + + test-compile + + + + + org.apache.maven.plugins maven-compiler-plugin + + + compile + compile + + compile + + + - -Xlint:all,-deprecation,-unchecked - -Xlint:none - true - false 1.8 1.8 @@ -895,7 +953,7 @@ -Xmx2G -classpath - + org.openjdk.jmh.Main .* -tu @@ -969,7 +1027,9 @@ process-resources - + @@ -1036,9 +1096,9 @@ 3 true https://raw.githubusercontent.com/wiki/lettuce-io/lettuce-core/ - - - + + + font coderay diff --git a/src/main/asciidoc/kotlin-api.asciidoc b/src/main/asciidoc/kotlin-api.asciidoc new file mode 100644 index 0000000000..d61827117d --- /dev/null +++ b/src/main/asciidoc/kotlin-api.asciidoc @@ -0,0 +1,38 @@ += Kotlin API + +=== Suspendable API based on either reactive or async operations + +Example for retrieving commands and using it: + +[source,kt] +---- +val cmd1: RedisSuspendableCommands = connection.async().asSuspendable() +val cmd2: RedisSuspendableCommands = connection.reactive().asSuspendable() + +val foo1 = cmd1.set("foo", "bar") +val foo2 = cmd2.keys("fo*") +---- + +=== Extensions for existing APIs + +==== Transactions DSL + +Example for sync: + +[source,kt] +---- +val result: TransactionResult? = connection.sync().multi { + set("foo", "bar") + get("foo") +} +---- + +Example for async with coroutines: + +[source,kt] +---- +val result: TransactionResult? = connection.async().multi { + set("foo", "bar").await() + get("foo").await() +} +---- diff --git a/src/main/kotlin/io/lettuce/core/ExperimentalLettuceCoroutinesApi.kt b/src/main/kotlin/io/lettuce/core/ExperimentalLettuceCoroutinesApi.kt new file mode 100644 index 0000000000..dd04265951 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/ExperimentalLettuceCoroutinesApi.kt @@ -0,0 +1,25 @@ +package io.lettuce.core + +import kotlin.RequiresOptIn.Level.WARNING +import kotlin.annotation.AnnotationRetention.BINARY +import kotlin.annotation.AnnotationTarget.* + +/** + * @author sokomishalov + */ +@RequiresOptIn(level = WARNING) +@Retention(BINARY) +@Target( + CLASS, + ANNOTATION_CLASS, + PROPERTY, + FIELD, + LOCAL_VARIABLE, + VALUE_PARAMETER, + CONSTRUCTOR, + FUNCTION, + PROPERTY_GETTER, + PROPERTY_SETTER, + TYPEALIAS +) +annotation class ExperimentalLettuceCoroutinesApi \ No newline at end of file diff --git a/src/main/kotlin/io/lettuce/core/api/async/RedisAsyncCommandsExtensions.kt b/src/main/kotlin/io/lettuce/core/api/async/RedisAsyncCommandsExtensions.kt new file mode 100644 index 0000000000..1b005ee4e7 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/async/RedisAsyncCommandsExtensions.kt @@ -0,0 +1,36 @@ +package io.lettuce.core.api.async + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.TransactionResult +import io.lettuce.core.api.coroutines.RedisSuspendableCommands +import io.lettuce.core.api.coroutines.async.RedisSuspendableAsyncCommandsImpl +import kotlinx.coroutines.future.await + + +/** + * Extension for [RedisAsyncCommands] to create [RedisSuspendableCommands] + * + * @author Mikhael Sokolov + * @since 6.0 + */ +@ExperimentalLettuceCoroutinesApi +fun RedisAsyncCommands.asSuspendable(): RedisSuspendableCommands { + return RedisSuspendableAsyncCommandsImpl(this) +} + +/** + * Allows to create transaction DSL block with [RedisAsyncCommands]. + * + * @author Mikhael Sokolov + * @since 6.0 + */ +@ExperimentalLettuceCoroutinesApi +suspend inline fun RedisAsyncCommands.multi(action: RedisAsyncCommands.() -> Unit): TransactionResult? { + multi().await() + runCatching { + action.invoke(this) + }.onFailure { + discard() + } + return exec().await() +} \ No newline at end of file diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/BaseRedisSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/BaseRedisSuspendableCommands.kt new file mode 100644 index 0000000000..0a99d877dd --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/BaseRedisSuspendableCommands.kt @@ -0,0 +1,201 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.protocol.CommandArgs +import io.lettuce.core.protocol.ProtocolKeyword +import io.lettuce.core.output.CommandOutput + + +/** + * Coroutine executed commands for basic commands. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface BaseRedisSuspendableCommands { + + /** + * Post a message to a channel. + * + * @param channel the channel type: key. + * @param message the message type: value. + * @return Long integer-reply the number of clients that received the message. + * + **/ + suspend fun publish(channel: K?, message: V?): Long? + + /** + * Lists the currently *active channels*. + * + * @return List array-reply a list of active channels, optionally matching the specified pattern. + * + **/ + suspend fun pubsubChannels(): List? + + /** + * Lists the currently *active channels*. + * + * @param channel the key. + * @return List array-reply a list of active channels, optionally matching the specified pattern. + * + **/ + suspend fun pubsubChannels(channel: K?): List? + + /** + * Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels. + * + * @param channels channel keys. + * @return array-reply a list of channels and number of subscribers for every channel. + * + **/ + suspend fun pubsubNumsub(vararg channels: K?): Map? + + /** + * Returns the number of subscriptions to patterns. + * + * @return Long integer-reply the number of patterns all the clients are subscribed to. + * + **/ + suspend fun pubsubNumpat(): Long? + + /** + * Echo the given string. + * + * @param msg the message type: value. + * @return V bulk-string-reply. + * + **/ + suspend fun echo(msg: V?): V? + + /** + * Return the role of the instance in the context of replication. + * + * @return List array-reply where the first element is one of master, slave, sentinel and the additional + * elements are role-specific. + * + **/ + suspend fun role(): List? + + /** + * Ping the server. + * + * @return String simple-string-reply. + * + **/ + suspend fun ping(): String? + + /** + * Switch connection to Read-Only mode when connecting to a cluster. + * + * @return String simple-string-reply. + * + **/ + suspend fun readOnly(): String? + + /** + * Switch connection to Read-Write mode (default) when connecting to a cluster. + * + * @return String simple-string-reply. + * + **/ + suspend fun readWrite(): String? + + /** + * Instructs Redis to disconnect the connection. Note that if auto-reconnect is enabled then Lettuce will auto-reconnect if + * the connection was disconnected. Use {@link io.lettuce.core.api.StatefulConnection#close} to close connections and + * release resources. + * + * @return String simple-string-reply always OK. + * + **/ + suspend fun quit(): String? + + /** + * Wait for replication. + * + * @param replicas minimum number of replicas. + * @param timeout timeout in milliseconds. + * @return number of replicas. + * + **/ + suspend fun waitForReplication(replicas: Int, timeout: Long): Long? + + /** + * Dispatch a command to the Redis Server. Please note the command output type must fit to the command response. + * + * @param type the command, must not be {@code null}. + * @param output the command output, must not be {@code null}. + * @param response type. + * @return the command response. + * + **/ + suspend fun dispatch(type: ProtocolKeyword?, output: CommandOutput?): T? + + /** + * Dispatch a command to the Redis Server. Please note the command output type must fit to the command response. + * + * @param type the command, must not be {@code null}. + * @param output the command output, must not be {@code null}. + * @param args the command arguments, must not be {@code null}. + * @param response type. + * @return the command response. + * + **/ + suspend fun dispatch(type: ProtocolKeyword?, output: CommandOutput?, args: CommandArgs?): T? + + /** + * + * @return @code true} if the connection is open (connected and not closed). + * + **/ + suspend fun isOpen(): Boolean + + /** + * Reset the command state. Queued commands will be canceled and the internal state will be reset. This is useful when the + * internal state machine gets out of sync with the connection. + * + **/ + suspend fun reset(): Unit? + + /** + * Disable or enable auto-flush behavior. Default is {@code true}. If autoFlushCommands is disabled, multiple commands can + * be issued without writing them actually to the transport. Commands are buffered until a {@link #flushCommands()} is + * issued. After calling {@link #flushCommands()} commands are sent to the transport and executed by Redis. + * + * @param autoFlush state of autoFlush. + * + **/ + suspend fun setAutoFlushCommands(autoFlush: Boolean): Unit? + + /** + * Flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to + * achieve batching. No-op if channel is not connected. + * + **/ + suspend fun flushCommands(): Unit? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisGeoSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisGeoSuspendableCommands.kt new file mode 100644 index 0000000000..0f3f7cdc4b --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisGeoSuspendableCommands.kt @@ -0,0 +1,180 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.* + + +/** + * Coroutine executed commands for the Geo-API. + * + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisGeoSuspendableCommands { + + /** + * Single geo add. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param member the member to add. + * @return Long integer-reply the number of elements that were added to the set. + * + **/ + suspend fun geoadd(key: K?, longitude: Double, latitude: Double, member: V?): Long? + + /** + * Multi geo add. + * + * @param key the key of the geo set. + * @param lngLatMember triplets of double longitude, double latitude and V member. + * @return Long integer-reply the number of elements that were added to the set. + * + **/ + suspend fun geoadd(key: K?, vararg lngLatMember: Any?): Long? + + /** + * Retrieve Geohash strings representing the position of one or more elements in a sorted set value representing a + * geospatial index. + * + * @param key the key of the geo set. + * @param members the members. + * @return bulk reply Geohash strings in the order of {@code members}. Returns {@code null} if a member is not found. + * + **/ + suspend fun geohash(key: K?, vararg members: V?): List>? + + /** + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param distance radius distance. + * @param unit distance unit. + * @return bulk reply. + * + **/ + suspend fun georadius(key: K?, longitude: Double, latitude: Double, distance: Double, unit: GeoArgs.Unit?): Set? + + /** + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param distance radius distance. + * @param unit distance unit. + * @param geoArgs args to control the result. + * @return nested multi-bulk reply. The {@link GeoWithin} contains only fields which were requested by {@link GeoArgs}. + * + **/ + suspend fun georadius(key: K?, longitude: Double, latitude: Double, distance: Double, unit: GeoArgs.Unit?, geoArgs: GeoArgs?): List>? + + /** + * Perform a {@link #georadius(Object, double, double, double, GeoArgs.Unit, GeoArgs)} query and store the results in a + * sorted set. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param distance radius distance. + * @param unit distance unit. + * @param geoRadiusStoreArgs args to store either the resulting elements with their distance or the resulting elements with + * their locations a sorted set. + * @return Long integer-reply the number of elements in the result. + * + **/ + suspend fun georadius(key: K?, longitude: Double, latitude: Double, distance: Double, unit: GeoArgs.Unit?, geoRadiusStoreArgs: GeoRadiusStoreArgs?): Long? + + /** + * Retrieve members selected by distance with the center of {@code member}. The member itself is always contained in the + * results. + * + * @param key the key of the geo set. + * @param member reference member. + * @param distance radius distance. + * @param unit distance unit. + * @return set of members. + * + **/ + suspend fun georadiusbymember(key: K?, member: V?, distance: Double, unit: GeoArgs.Unit?): Set? + + /** + * Retrieve members selected by distance with the center of {@code member}. The member itself is always contained in the + * results. + * + * @param key the key of the geo set. + * @param member reference member. + * @param distance radius distance. + * @param unit distance unit. + * @param geoArgs args to control the result. + * @return nested multi-bulk reply. The {@link GeoWithin} contains only fields which were requested by {@link GeoArgs}. + * + **/ + suspend fun georadiusbymember(key: K?, member: V?, distance: Double, unit: GeoArgs.Unit?, geoArgs: GeoArgs?): List>? + + /** + * Perform a {@link #georadiusbymember(Object, Object, double, GeoArgs.Unit, GeoArgs)} query and store the results in a + * sorted set. + * + * @param key the key of the geo set. + * @param member reference member. + * @param distance radius distance. + * @param unit distance unit. + * @param geoRadiusStoreArgs args to store either the resulting elements with their distance or the resulting elements with + * their locations a sorted set. + * @return Long integer-reply the number of elements in the result. + * + **/ + suspend fun georadiusbymember(key: K?, member: V?, distance: Double, unit: GeoArgs.Unit?, geoRadiusStoreArgs: GeoRadiusStoreArgs?): Long? + + /** + * Get geo coordinates for the {@code members}. + * + * @param key the key of the geo set. + * @param members the members. + * @return a list of {@link GeoCoordinates}s representing the x,y position of each element specified in the arguments. For + * missing elements {@code null} is returned. + * + **/ + suspend fun geopos(key: K?, vararg members: V?): List? + + /** + * Retrieve distance between points {@code from} and {@code to}. If one or more elements are missing {@code null} is + * returned. Default in meters by, otherwise according to {@code unit} + * + * @param key the key of the geo set. + * @param from from member. + * @param to to member. + * @param unit distance unit. + * @return distance between points {@code from} and {@code to}. If one or more elements are missing {@code null} is + * returned. + * + **/ + suspend fun geodist(key: K?, from: V?, to: V?, unit: GeoArgs.Unit?): Double? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHLLSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHLLSuspendableCommands.kt new file mode 100644 index 0000000000..b689e3d97b --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHLLSuspendableCommands.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi + + +/** + * Coroutine executed commands for HyperLogLog (PF* commands). + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisHLLSuspendableCommands { + + /** + * Adds the specified elements to the specified HyperLogLog. + * + * @param key the key. + * @param values the values. + * @return Long integer-reply specifically: + * + * 1 if at least 1 HyperLogLog internal register was altered. 0 otherwise. + * + **/ + suspend fun pfadd(key: K?, vararg values: V?): Long? + + /** + * Merge N different HyperLogLogs into a single one. + * + * @param destkey the destination key. + * @param sourcekeys the source key. + * @return String simple-string-reply The command just returns {@code OK}. + * + **/ + suspend fun pfmerge(destkey: K?, vararg sourcekeys: K?): String? + + /** + * Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s). + * + * @param keys the keys. + * @return Long integer-reply specifically: + * + * The approximated number of unique elements observed via {@code PFADD}. + * + **/ + suspend fun pfcount(vararg keys: K?): Long? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashSuspendableCommands.kt new file mode 100644 index 0000000000..edc1e59fb1 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisHashSuspendableCommands.kt @@ -0,0 +1,331 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.* +import io.lettuce.core.output.KeyStreamingChannel +import io.lettuce.core.output.KeyValueStreamingChannel +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands for Hashes (Key-Value pairs). + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisHashSuspendableCommands { + + /** + * Delete one or more hash fields. + * + * @param key the key. + * @param fields the field type: key. + * @return Long integer-reply the number of fields that were removed from the hash, not including specified but non existing + * fields. + * + **/ + suspend fun hdel(key: K?, vararg fields: K?): Long? + + /** + * Determine if a hash field exists. + * + * @param key the key. + * @param field the field type: key. + * @return Boolean integer-reply specifically: + * + * {@code true} if the hash contains {@code field}. {@code false} if the hash does not contain {@code field}, or + * {@code key} does not exist. + * + **/ + suspend fun hexists(key: K?, field: K?): Boolean? + + /** + * Get the value of a hash field. + * + * @param key the key. + * @param field the field type: key. + * @return V bulk-string-reply the value associated with {@code field}, or {@code null} when {@code field} is not present in + * the hash or {@code key} does not exist. + * + **/ + suspend fun hget(key: K?, field: K?): V? + + /** + * Increment the integer value of a hash field by the given number. + * + * @param key the key. + * @param field the field type: key. + * @param amount the increment type: long. + * @return Long integer-reply the value at {@code field} after the increment operation. + * + **/ + suspend fun hincrby(key: K?, field: K?, amount: Long): Long? + + /** + * Increment the float value of a hash field by the given amount. + * + * @param key the key. + * @param field the field type: key. + * @param amount the increment type: double. + * @return Double bulk-string-reply the value of {@code field} after the increment. + * + **/ + suspend fun hincrbyfloat(key: K?, field: K?, amount: Double): Double? + + /** + * Get all the fields and values in a hash. + * + * @param key the key. + * @return Map array-reply list of fields and their values stored in the hash, or an empty list when {@code key} + * does not exist. + * + **/ + suspend fun hgetall(key: K?): Map? + + /** + * Stream over all the fields and values in a hash. + * + * @param channel the channel. + * @param key the key. + * @return Long count of the keys. + * + **/ + suspend fun hgetall(channel: KeyValueStreamingChannel?, key: K?): Long? + + /** + * Get all the fields in a hash. + * + * @param key the key. + * @return List array-reply list of fields in the hash, or an empty list when {@code key} does not exist. + * + **/ + suspend fun hkeys(key: K?): List? + + /** + * Stream over all the fields in a hash. + * + * @param channel the channel. + * @param key the key. + * @return Long count of the keys. + * + **/ + suspend fun hkeys(channel: KeyStreamingChannel?, key: K?): Long? + + /** + * Get the number of fields in a hash. + * + * @param key the key. + * @return Long integer-reply number of fields in the hash, or {@code 0} when {@code key} does not exist. + * + **/ + suspend fun hlen(key: K?): Long? + + /** + * Get the values of all the given hash fields. + * + * @param key the key. + * @param fields the field type: key. + * @return List array-reply list of values associated with the given fields, in the same. + * + **/ + suspend fun hmget(key: K?, vararg fields: K?): List>? + + /** + * Stream over the values of all the given hash fields. + * + * @param channel the channel. + * @param key the key. + * @param fields the fields. + * @return Long count of the keys. + * + **/ + suspend fun hmget(channel: KeyValueStreamingChannel?, key: K?, vararg fields: K?): Long? + + /** + * Set multiple hash fields to multiple values. + * + * @param key the key. + * @param map the null. + * @return String simple-string-reply. + * + **/ + suspend fun hmset(key: K?, map: Map?): String? + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @return MapScanCursor map scan cursor. + * + **/ + suspend fun hscan(key: K?): MapScanCursor? + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @param scanArgs scan arguments. + * @return MapScanCursor map scan cursor. + * + **/ + suspend fun hscan(key: K?, scanArgs: ScanArgs?): MapScanCursor? + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return MapScanCursor map scan cursor. + * + **/ + suspend fun hscan(key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): MapScanCursor? + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return MapScanCursor map scan cursor. + * + **/ + suspend fun hscan(key: K?, scanCursor: ScanCursor?): MapScanCursor? + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?): StreamScanCursor? + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?, scanArgs: ScanArgs?): StreamScanCursor? + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?, scanCursor: ScanCursor?): StreamScanCursor? + + /** + * Set the string value of a hash field. + * + * @param key the key. + * @param field the field type: key. + * @param value the value. + * @return Boolean integer-reply specifically: + * + * {@code true} if {@code field} is a new field in the hash and {@code value} was set. {@code false} if + * {@code field} already exists in the hash and the value was updated. + * + **/ + suspend fun hset(key: K?, field: K?, value: V?): Boolean? + + /** + * Set multiple hash fields to multiple values. + * + * @param key the key of the hash. + * @param map the field/value pairs to update. + * @return Long integer-reply: the number of fields that were added. + * @since 5.3 + * + **/ + suspend fun hset(key: K?, map: Map?): Long? + + /** + * Set the value of a hash field, only if the field does not exist. + * + * @param key the key. + * @param field the field type: key. + * @param value the value. + * @return Boolean integer-reply specifically: + * + * {@code 1} if {@code field} is a new field in the hash and {@code value} was set. {@code 0} if {@code field} + * already exists in the hash and no operation was performed. + * + **/ + suspend fun hsetnx(key: K?, field: K?, value: V?): Boolean? + + /** + * Get the string length of the field value in a hash. + * + * @param key the key. + * @param field the field type: key. + * @return Long integer-reply the string length of the {@code field} value, or {@code 0} when {@code field} is not present + * in the hash or {@code key} does not exist at all. + * + **/ + suspend fun hstrlen(key: K?, field: K?): Long? + + /** + * Get all the values in a hash. + * + * @param key the key. + * @return List array-reply list of values in the hash, or an empty list when {@code key} does not exist. + * + **/ + suspend fun hvals(key: K?): List? + + /** + * Stream over all the values in a hash. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @return Long count of the keys. + * + **/ + suspend fun hvals(channel: ValueStreamingChannel?, key: K?): Long? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeySuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeySuspendableCommands.kt new file mode 100644 index 0000000000..da5305bbb3 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisKeySuspendableCommands.kt @@ -0,0 +1,466 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import java.util.Date +import io.lettuce.core.* +import io.lettuce.core.output.KeyStreamingChannel +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands for Keys (Key manipulation/querying). + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisKeySuspendableCommands { + + /** + * Delete one or more keys. + * + * @param keys the keys. + * @return Long integer-reply The number of keys that were removed. + * + **/ + suspend fun del(vararg keys: K?): Long? + + /** + * Unlink one or more keys (non blocking DEL). + * + * @param keys the keys. + * @return Long integer-reply The number of keys that were removed. + * + **/ + suspend fun unlink(vararg keys: K?): Long? + + /** + * Return a serialized version of the value stored at the specified key. + * + * @param key the key. + * @return byte[] bulk-string-reply the serialized value. + * + **/ + suspend fun dump(key: K?): ByteArray? + + /** + * Determine how many keys exist. + * + * @param keys the keys. + * @return Long integer-reply specifically: Number of existing keys. + * + **/ + suspend fun exists(vararg keys: K?): Long? + + /** + * Set a key's time to live in seconds. + * + * @param key the key. + * @param seconds the seconds type: long. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set. + * + **/ + suspend fun expire(key: K?, seconds: Long): Boolean? + + /** + * Set the expiration for a key as a UNIX timestamp. + * + * @param key the key. + * @param timestamp the timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + suspend fun expireat(key: K?, timestamp: Date?): Boolean? + + /** + * Set the expiration for a key as a UNIX timestamp. + * + * @param key the key. + * @param timestamp the timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + suspend fun expireat(key: K?, timestamp: Long): Boolean? + + /** + * Find all keys matching the given pattern. + * + * @param pattern the pattern type: patternkey (pattern). + * @return List array-reply list of keys matching {@code pattern}. + * + **/ + suspend fun keys(pattern: K?): List? + + /** + * Find all keys matching the given pattern. + * + * @param channel the channel. + * @param pattern the pattern. + * @return Long array-reply list of keys matching {@code pattern}. + * + **/ + suspend fun keys(channel: KeyStreamingChannel?, pattern: K?): Long? + + /** + * Atomically transfer a key from a Redis instance to another one. + * + * @param host the host. + * @param port the port. + * @param key the key. + * @param db the database. + * @param timeout the timeout in milliseconds. + * @return String simple-string-reply The command returns OK on success. + * + **/ + suspend fun migrate(host: String?, port: Int, key: K?, db: Int, timeout: Long): String? + + /** + * Atomically transfer one or more keys from a Redis instance to another one. + * + * @param host the host. + * @param port the port. + * @param db the database. + * @param timeout the timeout in milliseconds. + * @param migrateArgs migrate args that allow to configure further options. + * @return String simple-string-reply The command returns OK on success. + * + **/ + suspend fun migrate(host: String?, port: Int, db: Int, timeout: Long, migrateArgs: MigrateArgs?): String? + + /** + * Move a key to another database. + * + * @param key the key. + * @param db the db type: long. + * @return Boolean integer-reply specifically:. + * + **/ + suspend fun move(key: K?, db: Int): Boolean? + + /** + * returns the kind of internal representation used in order to store the value associated with a key. + * + * @param key the key. + * @return String. + * + **/ + suspend fun objectEncoding(key: K?): String? + + /** + * returns the number of seconds since the object stored at the specified key is idle (not requested by read or write + * operations). + * + * @param key the key. + * @return number of seconds since the object stored at the specified key is idle. + * + **/ + suspend fun objectIdletime(key: K?): Long? + + /** + * returns the number of references of the value associated with the specified key. + * + * @param key the key. + * @return Long. + * + **/ + suspend fun objectRefcount(key: K?): Long? + + /** + * Remove the expiration from a key. + * + * @param key the key. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was removed. {@code false} if {@code key} does not exist or does not have an + * associated timeout. + * + **/ + suspend fun persist(key: K?): Boolean? + + /** + * Set a key's time to live in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @return integer-reply, specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set. + * + **/ + suspend fun pexpire(key: K?, milliseconds: Long): Boolean? + + /** + * Set the expiration for a key as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + suspend fun pexpireat(key: K?, timestamp: Date?): Boolean? + + /** + * Set the expiration for a key as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + suspend fun pexpireat(key: K?, timestamp: Long): Boolean? + + /** + * Get the time to live for a key in milliseconds. + * + * @param key the key. + * @return Long integer-reply TTL in milliseconds, or a negative value in order to signal an error (see the description + * above). + * + **/ + suspend fun pttl(key: K?): Long? + + /** + * Return a random key from the keyspace. + * + * @return K bulk-string-reply the random key, or {@code null} when the database is empty. + * + **/ + suspend fun randomkey(): K? + + /** + * Rename a key. + * + * @param key the key. + * @param newKey the newkey type: key. + * @return String simple-string-reply. + * + **/ + suspend fun rename(key: K?, newKey: K?): String? + + /** + * Rename a key, only if the new key does not exist. + * + * @param key the key. + * @param newKey the newkey type: key. + * @return Boolean integer-reply specifically: + * + * {@code true} if {@code key} was renamed to {@code newkey}. {@code false} if {@code newkey} already exists. + * + **/ + suspend fun renamenx(key: K?, newKey: K?): Boolean? + + /** + * Create a key using the provided serialized value, previously obtained using DUMP. + * + * @param key the key. + * @param ttl the ttl type: long. + * @param value the serialized-value type: string. + * @return String simple-string-reply The command returns OK on success. + * + **/ + suspend fun restore(key: K?, ttl: Long, value: ByteArray?): String? + + /** + * Create a key using the provided serialized value, previously obtained using DUMP. + * + * @param key the key. + * @param value the serialized-value type: string. + * @param args the {@link RestoreArgs}, must not be {@code null}. + * @return String simple-string-reply The command returns OK on success. + * @since 5.1 + * + **/ + suspend fun restore(key: K?, value: ByteArray?, args: RestoreArgs?): String? + + /** + * Sort the elements in a list, set or sorted set. + * + * @param key the key. + * @return List array-reply list of sorted elements. + * + **/ + suspend fun sort(key: K?): List? + + /** + * Sort the elements in a list, set or sorted set. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @return Long number of values. + * + **/ + suspend fun sort(channel: ValueStreamingChannel?, key: K?): Long? + + /** + * Sort the elements in a list, set or sorted set. + * + * @param key the key. + * @param sortArgs sort arguments. + * @return List array-reply list of sorted elements. + * + **/ + suspend fun sort(key: K?, sortArgs: SortArgs?): List? + + /** + * Sort the elements in a list, set or sorted set. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param sortArgs sort arguments. + * @return Long number of values. + * + **/ + suspend fun sort(channel: ValueStreamingChannel?, key: K?, sortArgs: SortArgs?): Long? + + /** + * Sort the elements in a list, set or sorted set. + * + * @param key the key. + * @param sortArgs sort arguments. + * @param destination the destination key to store sort results. + * @return Long number of values. + * + **/ + suspend fun sortStore(key: K?, sortArgs: SortArgs?, destination: K?): Long? + + /** + * Touch one or more keys. Touch sets the last accessed time for a key. Non-exsitent keys wont get created. + * + * @param keys the keys. + * @return Long integer-reply the number of found keys. + * + **/ + suspend fun touch(vararg keys: K?): Long? + + /** + * Get the time to live for a key. + * + * @param key the key. + * @return Long integer-reply TTL in seconds, or a negative value in order to signal an error (see the description above). + * + **/ + suspend fun ttl(key: K?): Long? + + /** + * Determine the type stored at key. + * + * @param key the key. + * @return String simple-string-reply type of {@code key}, or {@code none} when {@code key} does not exist. + * + **/ + suspend fun type(key: K?): String? + + /** + * Incrementally iterate the keys space. + * + * @return KeyScanCursor scan cursor. + * + **/ + suspend fun scan(): KeyScanCursor? + + /** + * Incrementally iterate the keys space. + * + * @param scanArgs scan arguments. + * @return KeyScanCursor scan cursor. + * + **/ + suspend fun scan(scanArgs: ScanArgs?): KeyScanCursor? + + /** + * Incrementally iterate the keys space. + * + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return KeyScanCursor scan cursor. + * + **/ + suspend fun scan(scanCursor: ScanCursor?, scanArgs: ScanArgs?): KeyScanCursor? + + /** + * Incrementally iterate the keys space. + * + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return KeyScanCursor scan cursor. + * + **/ + suspend fun scan(scanCursor: ScanCursor?): KeyScanCursor? + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun scan(channel: KeyStreamingChannel?): StreamScanCursor? + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun scan(channel: KeyStreamingChannel?, scanArgs: ScanArgs?): StreamScanCursor? + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun scan(channel: KeyStreamingChannel?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun scan(channel: KeyStreamingChannel?, scanCursor: ScanCursor?): StreamScanCursor? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisListSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisListSuspendableCommands.kt new file mode 100644 index 0000000000..693023c109 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisListSuspendableCommands.kt @@ -0,0 +1,299 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.KeyValue +import io.lettuce.core.LPosArgs +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands for Lists. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisListSuspendableCommands { + + /** + * Remove and get the first element in a list, or block until one is available. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue array-reply specifically: + * + * A {@code null} multi-bulk when no element could be popped and the timeout expired. A two-element multi-bulk with + * the first element being the name of the key where an element was popped and the second element being the value of + * the popped element. + * + **/ + suspend fun blpop(timeout: Long, vararg keys: K?): KeyValue? + + /** + * Remove and get the last element in a list, or block until one is available. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue array-reply specifically: + * + * A {@code null} multi-bulk when no element could be popped and the timeout expired. A two-element multi-bulk with + * the first element being the name of the key where an element was popped and the second element being the value of + * the popped element. + * + **/ + suspend fun brpop(timeout: Long, vararg keys: K?): KeyValue? + + /** + * Pop a value from a list, push it to another list and return it; or block until one is available. + * + * @param timeout the timeout in seconds. + * @param source the source key. + * @param destination the destination type: key. + * @return V bulk-string-reply the element being popped from {@code source} and pushed to {@code destination}. If + * {@code timeout} is reached, a. + * + **/ + suspend fun brpoplpush(timeout: Long, source: K?, destination: K?): V? + + /** + * Get an element from a list by its index. + * + * @param key the key. + * @param index the index type: long. + * @return V bulk-string-reply the requested element, or {@code null} when {@code index} is out of range. + * + **/ + suspend fun lindex(key: K?, index: Long): V? + + /** + * Insert an element before or after another element in a list. + * + * @param key the key. + * @param before the before. + * @param pivot the pivot. + * @param value the value. + * @return Long integer-reply the length of the list after the insert operation, or {@code -1} when the value {@code pivot} + * was not found. + * + **/ + suspend fun linsert(key: K?, before: Boolean, pivot: V?, value: V?): Long? + + /** + * Get the length of a list. + * + * @param key the key. + * @return Long integer-reply the length of the list at {@code key}. + * + **/ + suspend fun llen(key: K?): Long? + + /** + * Remove and get the first element in a list. + * + * @param key the key. + * @return V bulk-string-reply the value of the first element, or {@code null} when {@code key} does not exist. + * + **/ + suspend fun lpop(key: K?): V? + + /** + * Return the index of matching elements inside a Redis list. By default, when no options are given, it will scan the list + * from head to tail, looking for the first match of "element". If the element is found, its index (the zero-based position + * in the list) is returned. Otherwise, if no match is found, {@code null} is returned. The returned elements indexes are + * always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is {@code 0}, + * and so forth. + * + * @param key the key. + * @param value the element to search for. + * @return V integer-reply representing the matching element, or null if there is no match. + * @since 5.3.2 + * + **/ + suspend fun lpos(key: K?, value: V?): Long? + + /** + * Return the index of matching elements inside a Redis list. By default, when no options are given, it will scan the list + * from head to tail, looking for the first match of "element". If the element is found, its index (the zero-based position + * in the list) is returned. Otherwise, if no match is found, {@code null} is returned. The returned elements indexes are + * always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is {@code 0}, + * and so forth. + * + * @param key the key. + * @param value the element to search for. + * @param args command arguments to configure{@code FIRST} and {@code MAXLEN} options. + * @return V integer-reply representing the matching element, or null if there is no match. + * @since 5.3.2 + * + **/ + suspend fun lpos(key: K?, value: V?, args: LPosArgs?): Long? + + /** + * Return the index of matching elements inside a Redis list using the {@code COUNT} option. By default, when no options are + * given, it will scan the list from head to tail, looking for the first match of "element". The returned elements indexes + * are always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is + * {@code 0}, and so forth. + * + * @param key the key. + * @param value the element to search for. + * @param count limit the number of matches. + * @return V integer-reply representing the matching elements, or empty if there is no match. + * @since 5.3.2 + * + **/ + suspend fun lpos(key: K?, value: V?, count: Int): List? + + /** + * Return the index of matching elements inside a Redis list using the {@code COUNT} option. By default, when no options are + * given, it will scan the list from head to tail, looking for the first match of "element". The returned elements indexes + * are always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is + * {@code 0}, and so forth. + * + * @param key the key. + * @param value the element to search for. + * @param count limit the number of matches. + * @param args command arguments to configure{@code FIRST} and {@code MAXLEN} options. + * @return V integer-reply representing the matching elements, or empty if there is no match. + * @since 5.3.2 + * + **/ + suspend fun lpos(key: K?, value: V?, count: Int, args: LPosArgs?): List? + + /** + * Prepend one or multiple values to a list. + * + * @param key the key. + * @param values the value. + * @return Long integer-reply the length of the list after the push operations. + * + **/ + suspend fun lpush(key: K?, vararg values: V?): Long? + + /** + * Prepend values to a list, only if the list exists. + * + * @param key the key. + * @param values the values. + * @return Long integer-reply the length of the list after the push operation. + * + **/ + suspend fun lpushx(key: K?, vararg values: V?): Long? + + /** + * Get a range of elements from a list. + * + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return List array-reply list of elements in the specified range. + * + **/ + suspend fun lrange(key: K?, start: Long, stop: Long): List? + + /** + * Get a range of elements from a list. + * + * @param channel the channel. + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return Long count of elements in the specified range. + * + **/ + suspend fun lrange(channel: ValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? + + /** + * Remove elements from a list. + * + * @param key the key. + * @param count the count type: long. + * @param value the value. + * @return Long integer-reply the number of removed elements. + * + **/ + suspend fun lrem(key: K?, count: Long, value: V?): Long? + + /** + * Set the value of an element in a list by its index. + * + * @param key the key. + * @param index the index type: long. + * @param value the value. + * @return String simple-string-reply. + * + **/ + suspend fun lset(key: K?, index: Long, value: V?): String? + + /** + * Trim a list to the specified range. + * + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return String simple-string-reply. + * + **/ + suspend fun ltrim(key: K?, start: Long, stop: Long): String? + + /** + * Remove and get the last element in a list. + * + * @param key the key. + * @return V bulk-string-reply the value of the last element, or {@code null} when {@code key} does not exist. + * + **/ + suspend fun rpop(key: K?): V? + + /** + * Remove the last element in a list, append it to another list and return it. + * + * @param source the source key. + * @param destination the destination type: key. + * @return V bulk-string-reply the element being popped and pushed. + * + **/ + suspend fun rpoplpush(source: K?, destination: K?): V? + + /** + * Append one or multiple values to a list. + * + * @param key the key. + * @param values the value. + * @return Long integer-reply the length of the list after the push operation. + * + **/ + suspend fun rpush(key: K?, vararg values: V?): Long? + + /** + * Append values to a list, only if the list exists. + * + * @param key the key. + * @param values the values. + * @return Long integer-reply the length of the list after the push operation. + * + **/ + suspend fun rpushx(key: K?, vararg values: V?): Long? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingSuspendableCommands.kt new file mode 100644 index 0000000000..4a7c9760b0 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingSuspendableCommands.kt @@ -0,0 +1,184 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.ScriptOutputType + + +/** + * Coroutine executed commands for Scripting. {@link java.lang.String Lua scripts} are encoded by using the configured + * {@link io.lettuce.core.ClientOptions#getScriptCharset() charset}. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisScriptingSuspendableCommands { + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type output type. + * @param keys key names. + * @param expected return type. + * @return script result. + * + **/ + suspend fun eval(script: String?, type: ScriptOutputType?, vararg keys: K?): T? + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type output type. + * @param keys key names. + * @param expected return type. + * @return script result. + * @since 6.0 + * + **/ + suspend fun eval(script: ByteArray?, type: ScriptOutputType?, vararg keys: K?): T? + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type the type. + * @param keys the keys. + * @param values the values. + * @param expected return type. + * @return script result. + * + **/ + suspend fun eval(script: String?, type: ScriptOutputType?, keys: Array?, vararg values: V?): T? + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type the type. + * @param keys the keys. + * @param values the values. + * @param expected return type. + * @return script result. + * @since 6.0 + * + **/ + suspend fun eval(script: ByteArray?, type: ScriptOutputType?, keys: Array?, vararg values: V?): T? + + /** + * Evaluates a script cached on the server side by its SHA1 digest. + * + * @param digest SHA1 of the script. + * @param type the type. + * @param keys the keys. + * @param expected return type. + * @return script result. + * + **/ + suspend fun evalsha(digest: String?, type: ScriptOutputType?, vararg keys: K?): T? + + /** + * Execute a Lua script server side. + * + * @param digest SHA1 of the script. + * @param type the type. + * @param keys the keys. + * @param values the values. + * @param expected return type. + * @return script result. + * + **/ + suspend fun evalsha(digest: String?, type: ScriptOutputType?, keys: Array?, vararg values: V?): T? + + /** + * Check existence of scripts in the script cache. + * + * @param digests script digests. + * @return List array-reply The command returns an array of integers that correspond to the specified SHA1 + * digest arguments. For every corresponding SHA1 digest of a script that actually exists in the script cache, an 1 + * is returned, otherwise 0 is returned. + * + **/ + suspend fun scriptExists(vararg digests: String?): List? + + /** + * Remove all the scripts from the script cache. + * + * @return String simple-string-reply. + * + **/ + suspend fun scriptFlush(): String? + + /** + * Kill the script currently in execution. + * + * @return String simple-string-reply. + * + **/ + suspend fun scriptKill(): String? + + /** + * Load the specified Lua script into the script cache. + * + * @param script script content. + * @return String bulk-string-reply This command returns the SHA1 digest of the script added into the script cache. + * @since 6.0 + * + **/ + suspend fun scriptLoad(script: String?): String? + + /** + * Load the specified Lua script into the script cache. + * + * @param script script content. + * @return String bulk-string-reply This command returns the SHA1 digest of the script added into the script cache. + * @since 6.0 + * + **/ + suspend fun scriptLoad(script: ByteArray?): String? + + /** + * Create a SHA1 digest from a Lua script. + * + * @param script script content. + * @return the SHA1 value. + * @since 6.0 + * + **/ + suspend fun digest(script: String?): String? + + /** + * Create a SHA1 digest from a Lua script. + * + * @param script script content. + * @return the SHA1 value. + * @since 6.0 + * + **/ + suspend fun digest(script: ByteArray?): String? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerSuspendableCommands.kt new file mode 100644 index 0000000000..6f8f117a7f --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerSuspendableCommands.kt @@ -0,0 +1,455 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import java.util.Date +import io.lettuce.core.KillArgs +import io.lettuce.core.TrackingArgs +import io.lettuce.core.UnblockType +import io.lettuce.core.protocol.CommandType + + +/** + * Coroutine executed commands for Server Control. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisServerSuspendableCommands { + + /** + * Asynchronously rewrite the append-only file. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + suspend fun bgrewriteaof(): String? + + /** + * Asynchronously save the dataset to disk. + * + * @return String simple-string-reply. + * + **/ + suspend fun bgsave(): String? + + /** + * Control tracking of keys in the context of server-assisted client cache invalidation. + * + * @param enabled @code true} to enable key tracking. + * @return String simple-string-reply {@code OK}. + * @since 6.0 + * + **/ + suspend fun clientCaching(enabled: Boolean): String? + + /** + * Get the current connection name. + * + * @return K bulk-string-reply The connection name, or a null bulk reply if no name is set. + * + **/ + suspend fun clientGetname(): K? + + /** + * Returns the client ID we are redirecting our tracking notifications to. + * + * @return the ID of the client we are redirecting the notifications to. The command returns -1 if client tracking is not + * enabled, or 0 if client tracking is enabled but we are not redirecting the notifications to any client. + * @since 6.0 + * + **/ + suspend fun clientGetredir(): Long? + + /** + * Get the id of the current connection. + * + * @return Long The command just returns the ID of the current connection. + * @since 5.3 + * + **/ + suspend fun clientId(): Long? + + /** + * Kill the connection of a client identified by ip:port. + * + * @param addr ip:port. + * @return String simple-string-reply {@code OK} if the connection exists and has been closed. + * + **/ + suspend fun clientKill(addr: String?): String? + + /** + * Kill connections of clients which are filtered by {@code killArgs}. + * + * @param killArgs args for the kill operation. + * @return Long integer-reply number of killed connections. + * + **/ + suspend fun clientKill(killArgs: KillArgs?): Long? + + /** + * Get the list of client connections. + * + * @return String bulk-string-reply a unique string, formatted as follows: One client connection per line (separated by LF), + * each line is composed of a succession of property=value fields separated by a space character. + * + **/ + suspend fun clientList(): String? + + /** + * Stop processing commands from clients for some time. + * + * @param timeout the timeout value in milliseconds. + * @return String simple-string-reply The command returns OK or an error if the timeout is invalid. + * + **/ + suspend fun clientPause(timeout: Long): String? + + /** + * Set the current connection name. + * + * @param name the client name. + * @return simple-string-reply {@code OK} if the connection name was successfully set. + * + **/ + suspend fun clientSetname(name: K?): String? + + /** + * Enables the tracking feature of the Redis server, that is used for server assisted client side caching. Tracking messages + * are either available when using the RESP3 protocol or through Pub/Sub notification when using RESP2. + * + * @param args for the CLIENT TRACKING operation. + * @return String simple-string-reply {@code OK}. + * @since 6.0 + * + **/ + suspend fun clientTracking(args: TrackingArgs?): String? + + /** + * Unblock the specified blocked client. + * + * @param id the client id. + * @param type unblock type. + * @return Long integer-reply number of unblocked connections. + * @since 5.1 + * + **/ + suspend fun clientUnblock(id: Long, type: UnblockType?): Long? + + /** + * Returns an array reply of details about all Redis commands. + * + * @return List array-reply. + * + **/ + suspend fun command(): List? + + /** + * Get total number of Redis commands. + * + * @return Long integer-reply of number of total commands in this Redis server. + * + **/ + suspend fun commandCount(): Long? + + /** + * Returns an array reply of details about the requested commands. + * + * @param commands the commands to query for. + * @return List array-reply. + * + **/ + suspend fun commandInfo(vararg commands: String?): List? + + /** + * Returns an array reply of details about the requested commands. + * + * @param commands the commands to query for. + * @return List array-reply. + * + **/ + suspend fun commandInfo(vararg commands: CommandType?): List? + + /** + * Get the value of a configuration parameter. + * + * @param parameter name of the parameter. + * @return Map bulk-string-reply. + * + **/ + suspend fun configGet(parameter: String?): Map? + + /** + * Reset the stats returned by INFO. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + suspend fun configResetstat(): String? + + /** + * Rewrite the configuration file with the in memory configuration. + * + * @return String simple-string-reply {@code OK} when the configuration was rewritten properly. Otherwise an error is + * returned. + * + **/ + suspend fun configRewrite(): String? + + /** + * Set a configuration parameter to the given value. + * + * @param parameter the parameter name. + * @param value the parameter value. + * @return String simple-string-reply: {@code OK} when the configuration was set properly. Otherwise an error is returned. + * + **/ + suspend fun configSet(parameter: String?, value: String?): String? + + /** + * Return the number of keys in the selected database. + * + * @return Long integer-reply. + * + **/ + suspend fun dbsize(): Long? + + /** + * Crash and recover. + * + * @param delay optional delay in milliseconds. + * @return String simple-string-reply. + * + **/ + suspend fun debugCrashAndRecover(delay: Long?): String? + + /** + * Get debugging information about the internal hash-table state. + * + * @param db the database number. + * @return String simple-string-reply. + * + **/ + suspend fun debugHtstats(db: Int): String? + + /** + * Get debugging information about a key. + * + * @param key the key. + * @return String simple-string-reply. + * + **/ + suspend fun debugObject(key: K?): String? + + /** + * Make the server crash: Out of memory. + * + * @return nothing, because the server crashes before returning. + * + **/ + suspend fun debugOom(): Unit? + + /** + * Save RDB, clear the database and reload RDB. + * + * @return String simple-string-reply The commands returns OK on success. + * + **/ + suspend fun debugReload(): String? + + /** + * Restart the server gracefully. + * + * @param delay optional delay in milliseconds. + * @return String simple-string-reply. + * + **/ + suspend fun debugRestart(delay: Long?): String? + + /** + * Get debugging information about the internal SDS length. + * + * @param key the key. + * @return String simple-string-reply. + * + **/ + suspend fun debugSdslen(key: K?): String? + + /** + * Make the server crash: Invalid pointer access. + * + * @return nothing, because the server crashes before returning. + * + **/ + suspend fun debugSegfault(): Unit? + + /** + * Remove all keys from all databases. + * + * @return String simple-string-reply. + * + **/ + suspend fun flushall(): String? + + /** + * Remove all keys asynchronously from all databases. + * + * @return String simple-string-reply. + * + **/ + suspend fun flushallAsync(): String? + + /** + * Remove all keys from the current database. + * + * @return String simple-string-reply. + * + **/ + suspend fun flushdb(): String? + + /** + * Remove all keys asynchronously from the current database. + * + * @return String simple-string-reply. + * + **/ + suspend fun flushdbAsync(): String? + + /** + * Get information and statistics about the server. + * + * @return String bulk-string-reply as a collection of text lines. + * + **/ + suspend fun info(): String? + + /** + * Get information and statistics about the server. + * + * @param section the section type: string. + * @return String bulk-string-reply as a collection of text lines. + * + **/ + suspend fun info(section: String?): String? + + /** + * Get the UNIX time stamp of the last successful save to disk. + * + * @return Date integer-reply an UNIX time stamp. + * + **/ + suspend fun lastsave(): Date? + + /** + * Reports the number of bytes that a key and its value require to be stored in RAM. + * + * @return memory usage in bytes. + * @since 5.2 + * + **/ + suspend fun memoryUsage(key: K?): Long? + + /** + * Synchronously save the dataset to disk. + * + * @return String simple-string-reply The commands returns OK on success. + * + **/ + suspend fun save(): String? + + /** + * Synchronously save the dataset to disk and then shut down the server. + * + * @param save @code true} force save operation. + * + **/ + suspend fun shutdown(save: Boolean): Unit? + + /** + * Make the server a replica of another instance, or promote it as master. + * + * @param host the host type: string. + * @param port the port type: string. + * @return String simple-string-reply. + * + **/ + suspend fun slaveof(host: String?, port: Int): String? + + /** + * Promote server as master. + * + * @return String simple-string-reply. + * + **/ + suspend fun slaveofNoOne(): String? + + /** + * Read the slow log. + * + * @return List deeply nested multi bulk replies. + * + **/ + suspend fun slowlogGet(): List? + + /** + * Read the slow log. + * + * @param count the count. + * @return List deeply nested multi bulk replies. + * + **/ + suspend fun slowlogGet(count: Int): List? + + /** + * Obtaining the current length of the slow log. + * + * @return Long length of the slow log. + * + **/ + suspend fun slowlogLen(): Long? + + /** + * Resetting the slow log. + * + * @return String simple-string-reply The commands returns OK on success. + * + **/ + suspend fun slowlogReset(): String? + + /** + * Return the current server time. + * + * @return List array-reply specifically: + * + * A multi bulk reply containing two elements: + * + * unix time in seconds. microseconds. + * + **/ + suspend fun time(): List? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSetSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSetSuspendableCommands.kt new file mode 100644 index 0000000000..7226ec29f6 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSetSuspendableCommands.kt @@ -0,0 +1,342 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.ScanArgs +import io.lettuce.core.ScanCursor +import io.lettuce.core.StreamScanCursor +import io.lettuce.core.ValueScanCursor +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands for Sets. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisSetSuspendableCommands { + + /** + * Add one or more members to a set. + * + * @param key the key. + * @param members the member type: value. + * @return Long integer-reply the number of elements that were added to the set, not including all the elements already + * present into the set. + * + **/ + suspend fun sadd(key: K?, vararg members: V?): Long? + + /** + * Get the number of members in a set. + * + * @param key the key. + * @return Long integer-reply the cardinality (number of elements) of the set, or {@code false} if {@code key} does not + * exist. + * + **/ + suspend fun scard(key: K?): Long? + + /** + * Subtract multiple sets. + * + * @param keys the key. + * @return Set array-reply list with members of the resulting set. + * + **/ + suspend fun sdiff(vararg keys: K?): Set? + + /** + * Subtract multiple sets. + * + * @param channel the channel. + * @param keys the keys. + * @return Long count of members of the resulting set. + * + **/ + suspend fun sdiff(channel: ValueStreamingChannel?, vararg keys: K?): Long? + + /** + * Subtract multiple sets and store the resulting set in a key. + * + * @param destination the destination type: key. + * @param keys the key. + * @return Long integer-reply the number of elements in the resulting set. + * + **/ + suspend fun sdiffstore(destination: K?, vararg keys: K?): Long? + + /** + * Intersect multiple sets. + * + * @param keys the key. + * @return Set array-reply list with members of the resulting set. + * + **/ + suspend fun sinter(vararg keys: K?): Set? + + /** + * Intersect multiple sets. + * + * @param channel the channel. + * @param keys the keys. + * @return Long count of members of the resulting set. + * + **/ + suspend fun sinter(channel: ValueStreamingChannel?, vararg keys: K?): Long? + + /** + * Intersect multiple sets and store the resulting set in a key. + * + * @param destination the destination type: key. + * @param keys the key. + * @return Long integer-reply the number of elements in the resulting set. + * + **/ + suspend fun sinterstore(destination: K?, vararg keys: K?): Long? + + /** + * Determine if a given value is a member of a set. + * + * @param key the key. + * @param member the member type: value. + * @return Boolean integer-reply specifically: + * + * {@code true} if the element is a member of the set. {@code false} if the element is not a member of the set, or + * if {@code key} does not exist. + * + **/ + suspend fun sismember(key: K?, member: V?): Boolean? + + /** + * Move a member from one set to another. + * + * @param source the source key. + * @param destination the destination type: key. + * @param member the member type: value. + * @return Boolean integer-reply specifically: + * + * {@code true} if the element is moved. {@code false} if the element is not a member of {@code source} and no + * operation was performed. + * + **/ + suspend fun smove(source: K?, destination: K?, member: V?): Boolean? + + /** + * Get all the members in a set. + * + * @param key the key. + * @return Set array-reply all elements of the set. + * + **/ + suspend fun smembers(key: K?): Set? + + /** + * Get all the members in a set. + * + * @param channel the channel. + * @param key the keys. + * @return Long count of members of the resulting set. + * + **/ + suspend fun smembers(channel: ValueStreamingChannel?, key: K?): Long? + + /** + * Remove and return a random member from a set. + * + * @param key the key. + * @return V bulk-string-reply the removed element, or {@code null} when {@code key} does not exist. + * + **/ + suspend fun spop(key: K?): V? + + /** + * Remove and return one or multiple random members from a set. + * + * @param key the key. + * @param count number of members to pop. + * @return V bulk-string-reply the removed element, or {@code null} when {@code key} does not exist. + * + **/ + suspend fun spop(key: K?, count: Long): Set? + + /** + * Get one random member from a set. + * + * @param key the key. + * @return V bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply with the + * randomly selected element, or {@code null} when {@code key} does not exist. + * + **/ + suspend fun srandmember(key: K?): V? + + /** + * Get one or multiple random members from a set. + * + * @param key the key. + * @param count the count type: long. + * @return Set bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply + * with the randomly selected element, or {@code null} when {@code key} does not exist. + * + **/ + suspend fun srandmember(key: K?, count: Long): List? + + /** + * Get one or multiple random members from a set. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param count the count. + * @return Long count of members of the resulting set. + * + **/ + suspend fun srandmember(channel: ValueStreamingChannel?, key: K?, count: Long): Long? + + /** + * Remove one or more members from a set. + * + * @param key the key. + * @param members the member type: value. + * @return Long integer-reply the number of members that were removed from the set, not including non existing members. + * + **/ + suspend fun srem(key: K?, vararg members: V?): Long? + + /** + * Add multiple sets. + * + * @param keys the key. + * @return Set array-reply list with members of the resulting set. + * + **/ + suspend fun sunion(vararg keys: K?): Set? + + /** + * Add multiple sets. + * + * @param channel streaming channel that receives a call for every value. + * @param keys the keys. + * @return Long count of members of the resulting set. + * + **/ + suspend fun sunion(channel: ValueStreamingChannel?, vararg keys: K?): Long? + + /** + * Add multiple sets and store the resulting set in a key. + * + * @param destination the destination type: key. + * @param keys the key. + * @return Long integer-reply the number of elements in the resulting set. + * + **/ + suspend fun sunionstore(destination: K?, vararg keys: K?): Long? + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @return ValueScanCursor scan cursor. + * + **/ + suspend fun sscan(key: K?): ValueScanCursor? + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @param scanArgs scan arguments. + * @return ValueScanCursor scan cursor. + * + **/ + suspend fun sscan(key: K?, scanArgs: ScanArgs?): ValueScanCursor? + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return ValueScanCursor scan cursor. + * + **/ + suspend fun sscan(key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): ValueScanCursor? + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return ValueScanCursor scan cursor. + * + **/ + suspend fun sscan(key: K?, scanCursor: ScanCursor?): ValueScanCursor? + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun sscan(channel: ValueStreamingChannel?, key: K?): StreamScanCursor? + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun sscan(channel: ValueStreamingChannel?, key: K?, scanArgs: ScanArgs?): StreamScanCursor? + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun sscan(channel: ValueStreamingChannel?, key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun sscan(channel: ValueStreamingChannel?, key: K?, scanCursor: ScanCursor?): StreamScanCursor? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetSuspendableCommands.kt new file mode 100644 index 0000000000..517e96462e --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetSuspendableCommands.kt @@ -0,0 +1,1363 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.* +import io.lettuce.core.output.ScoredValueStreamingChannel +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands for Sorted Sets. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisSortedSetSuspendableCommands { + + /** + * Removes and returns a member with the lowest scores in the sorted set stored at one of the keys. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue> multi-bulk containing the name of the key, the score and the popped + * member. + * @since 5.1 + * + **/ + suspend fun bzpopmin(timeout: Long, vararg keys: K?): KeyValue>? + + /** + * Removes and returns a member with the highest scores in the sorted set stored at one of the keys. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue> multi-bulk containing the name of the key, the score and the popped + * member. + * @since 5.1 + * + **/ + suspend fun bzpopmax(timeout: Long, vararg keys: K?): KeyValue>? + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + suspend fun zadd(key: K?, score: Double, member: V?): Long? + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param scoresAndValues the scoresAndValue tuples (score,value,score,value,...). + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + suspend fun zadd(key: K?, vararg scoresAndValues: Any?): Long? + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param scoredValues the scored values. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + suspend fun zadd(key: K?, vararg scoredValues: ScoredValue?): Long? + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param zAddArgs arguments for zadd. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + suspend fun zadd(key: K?, zAddArgs: ZAddArgs?, score: Double, member: V?): Long? + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param zAddArgs arguments for zadd. + * @param scoresAndValues the scoresAndValue tuples (score,value,score,value,...). + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + suspend fun zadd(key: K?, zAddArgs: ZAddArgs?, vararg scoresAndValues: Any?): Long? + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the ke. + * @param zAddArgs arguments for zadd. + * @param scoredValues the scored values. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + suspend fun zadd(key: K?, zAddArgs: ZAddArgs?, vararg scoredValues: ScoredValue?): Long? + + /** + * Add one or more members to a sorted set, or update its score if it already exists applying the {@code INCR} option. ZADD + * acts like ZINCRBY. + * + * @param key the key. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: The total number of elements changed. + * + **/ + suspend fun zaddincr(key: K?, score: Double, member: V?): Double? + + /** + * Add one or more members to a sorted set, or update its score if it already exists applying the {@code INCR} option. ZADD + * acts like ZINCRBY. + * + * @param key the key. + * @param zAddArgs arguments for zadd. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: The total number of elements changed. + * @since 4.3 + * + **/ + suspend fun zaddincr(key: K?, zAddArgs: ZAddArgs?, score: Double, member: V?): Double? + + /** + * Get the number of members in a sorted set. + * + * @param key the key. + * @return Long integer-reply the cardinality (number of elements) of the sorted set, or {@code false} if {@code key} does + * not exist. + * + **/ + suspend fun zcard(key: K?): Long? + + /** + * Count the members in a sorted set with scores within the given values. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements in the specified score range. + * @deprecated Use {@link #zcount(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zcount(key: K?, min: Double, max: Double): Long? + + /** + * Count the members in a sorted set with scores within the given values. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements in the specified score range. + * @deprecated Use {@link #zcount(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zcount(key: K?, min: String?, max: String?): Long? + + /** + * Count the members in a sorted set with scores within the given {@link Range}. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zcount(key: K?, range: Range?): Long? + + /** + * Increment the score of a member in a sorted set. + * + * @param key the key. + * @param amount the increment type: long. + * @param member the member type: value. + * @return Double bulk-string-reply the new score of {@code member} (a double precision floating point number), represented + * as string. + * + **/ + suspend fun zincrby(key: K?, amount: Double, member: V?): Double? + + /** + * Intersect multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination the destination. + * @param keys the keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + suspend fun zinterstore(destination: K?, vararg keys: K?): Long? + + /** + * Intersect multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination the destination. + * @param storeArgs the storeArgs. + * @param keys the keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + suspend fun zinterstore(destination: K?, storeArgs: ZStoreArgs?, vararg keys: K?): Long? + + /** + * Count the number of members in a sorted set between a given lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements in the specified score range. + * @deprecated Use {@link #zlexcount(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zlexcount(key: K?, min: String?, max: String?): Long? + + /** + * Count the number of members in a sorted set between a given lexicographical range. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zlexcount(key: K?, range: Range?): Long? + + /** + * Removes and returns up to count members with the lowest scores in the sorted set stored at key. + * + * @param key the key. + * @return ScoredValue the removed element. + * @since 5.1 + * + **/ + suspend fun zpopmin(key: K?): ScoredValue? + + /** + * Removes and returns up to count members with the lowest scores in the sorted set stored at key. + * + * @param key the key. + * @param count the number of elements to return. + * @return List> array-reply list of popped scores and elements. + * @since 5.1 + * + **/ + suspend fun zpopmin(key: K?, count: Long): List>? + + /** + * Removes and returns up to count members with the highest scores in the sorted set stored at key. + * + * @param key the key. + * @return ScoredValue the removed element. + * @since 5.1 + * + **/ + suspend fun zpopmax(key: K?): ScoredValue? + + /** + * Removes and returns up to count members with the highest scores in the sorted set stored at key. + * + * @param key the key. + * @param count the number of elements to return. + * @return List> array-reply list of popped scores and elements. + * @since 5.1 + * + **/ + suspend fun zpopmax(key: K?, count: Long): List>? + + /** + * Return a range of members in a sorted set, by index. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + suspend fun zrange(key: K?, start: Long, stop: Long): List? + + /** + * Return a range of members in a sorted set, by index. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + suspend fun zrange(channel: ValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? + + /** + * Return a range of members with scores in a sorted set, by index. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + suspend fun zrangeWithScores(key: K?, start: Long, stop: Long): List>? + + /** + * Stream over a range of members with scores in a sorted set, by index. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + suspend fun zrangeWithScores(channel: ScoredValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified range. + * @deprecated Use {@link #zrangebylex(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebylex(key: K?, min: String?, max: String?): List? + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified range. + * @since 4.3 + * + **/ + suspend fun zrangebylex(key: K?, range: Range?): List? + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified range. + * @deprecated Use {@link #zrangebylex(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebylex(key: K?, min: String?, max: String?, offset: Long, count: Long): List? + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified range. + * @since 4.3 + * + **/ + suspend fun zrangebylex(key: K?, range: Range?, limit: Limit?): List? + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscore(key: K?, min: Double, max: Double): List? + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscore(key: K?, min: String?, max: String?): List? + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrangebyscore(key: K?, range: Range?): List? + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscore(key: K?, min: Double, max: Double, offset: Long, count: Long): List? + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscore(key: K?, min: String?, max: String?, offset: Long, count: Long): List? + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrangebyscore(key: K?, range: Range?, limit: Limit?): List? + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: Double, max: Double): Long? + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: String?, max: String?): Long? + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?): Long? + + /** + * Stream over range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: Double, max: Double, offset: Long, count: Long): Long? + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: String?, max: String?, offset: Long, count: Long): Long? + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscoreWithScores(key: K?, min: Double, max: Double): List>? + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscoreWithScores(key: K?, min: String?, max: String?): List>? + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @return List> array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrangebyscoreWithScores(key: K?, range: Range?): List>? + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscoreWithScores(key: K?, min: Double, max: Double, offset: Long, count: Long): List>? + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscoreWithScores(key: K?, min: String?, max: String?, offset: Long, count: Long): List>? + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List> array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrangebyscoreWithScores(key: K?, range: Range?, limit: Limit?): List>? + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: Double, max: Double): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: String?, max: String?): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: Double, max: Double, offset: Long, count: Long): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: String?, max: String?, offset: Long, count: Long): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? + + /** + * Determine the index of a member in a sorted set. + * + * @param key the key. + * @param member the member type: value. + * @return Long integer-reply the rank of {@code member}. If {@code member} does not exist in the sorted set or {@code key} + * does not exist,. + * + **/ + suspend fun zrank(key: K?, member: V?): Long? + + /** + * Remove one or more members from a sorted set. + * + * @param key the key. + * @param members the member type: value. + * @return Long integer-reply specifically: + * + * The number of members removed from the sorted set, not including non existing members. + * + **/ + suspend fun zrem(key: K?, vararg members: V?): Long? + + /** + * Remove all members in a sorted set between the given lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements removed. + * @deprecated Use {@link #zremrangebylex(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zremrangebylex(key: K?, min: String?, max: String?): Long? + + /** + * Remove all members in a sorted set between the given lexicographical range. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements removed. + * @since 4.3 + * + **/ + suspend fun zremrangebylex(key: K?, range: Range?): Long? + + /** + * Remove all members in a sorted set within the given indexes. + * + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return Long integer-reply the number of elements removed. + * + **/ + suspend fun zremrangebyrank(key: K?, start: Long, stop: Long): Long? + + /** + * Remove all members in a sorted set within the given scores. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements removed. + * @deprecated Use {@link #zremrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zremrangebyscore(key: K?, min: Double, max: Double): Long? + + /** + * Remove all members in a sorted set within the given scores. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements removed. + * @deprecated Use {@link #zremrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zremrangebyscore(key: K?, min: String?, max: String?): Long? + + /** + * Remove all members in a sorted set within the given scores. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements removed. + * @since 4.3 + * + **/ + suspend fun zremrangebyscore(key: K?, range: Range?): Long? + + /** + * Return a range of members in a sorted set, by index, with scores ordered from high to low. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + suspend fun zrevrange(key: K?, start: Long, stop: Long): List? + + /** + * Stream over a range of members in a sorted set, by index, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + suspend fun zrevrange(channel: ValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? + + /** + * Return a range of members with scores in a sorted set, by index, with scores ordered from high to low. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + suspend fun zrevrangeWithScores(key: K?, start: Long, stop: Long): List>? + + /** + * Stream over a range of members with scores in a sorted set, by index, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + suspend fun zrevrangeWithScores(channel: ScoredValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? + + /** + * Return a range of members in a sorted set, by lexicographical range ordered from high to low. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrevrangebylex(key: K?, range: Range?): List? + + /** + * Return a range of members in a sorted set, by lexicographical range ordered from high to low. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrevrangebylex(key: K?, range: Range?, limit: Limit?): List? + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscore(key: K?, max: Double, min: Double): List? + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscore(key: K?, max: String?, min: String?): List? + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrevrangebyscore(key: K?, range: Range?): List? + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the withscores. + * @param count the null. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscore(key: K?, max: Double, min: Double, offset: Long, count: Long): List? + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscore(key: K?, max: String?, min: String?, offset: Long, count: Long): List? + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrevrangebyscore(key: K?, range: Range?, limit: Limit?): List? + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param max max score. + * @param min min score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: Double, min: Double): Long? + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: String?, min: String?): Long? + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified range. + * @since 4.3 + * + **/ + suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?): Long? + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: Double, min: Double, offset: Long, count: Long): Long? + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: String?, min: String?, offset: Long, count: Long): Long? + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified range. + * @since 4.3 + * + **/ + suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscoreWithScores(key: K?, max: Double, min: Double): List>? + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscoreWithScores(key: K?, max: String?, min: String?): List>? + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @return List> array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrevrangebyscoreWithScores(key: K?, range: Range?): List>? + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the offset. + * @param count the count. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscoreWithScores(key: K?, max: Double, min: Double, offset: Long, count: Long): List>? + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscoreWithScores(key: K?, max: String?, min: String?, offset: Long, count: Long): List>? + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @param limit limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + suspend fun zrevrangebyscoreWithScores(key: K?, range: Range?, limit: Limit?): List>? + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: Double, min: Double): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: String?, min: String?): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified range. + * + **/ + suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: Double, min: Double, offset: Long, count: Long): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: String?, min: String?, offset: Long, count: Long): Long? + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified range. + * @since 4.3 + * + **/ + suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? + + /** + * Determine the index of a member in a sorted set, with scores ordered from high to low. + * + * @param key the key. + * @param member the member type: value. + * @return Long integer-reply the rank of {@code member}. If {@code member} does not exist in the sorted set or {@code key} + * does not exist,. + * + **/ + suspend fun zrevrank(key: K?, member: V?): Long? + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @return ScoredValueScanCursor scan cursor. + * + **/ + suspend fun zscan(key: K?): ScoredValueScanCursor? + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @param scanArgs scan arguments. + * @return ScoredValueScanCursor scan cursor. + * + **/ + suspend fun zscan(key: K?, scanArgs: ScanArgs?): ScoredValueScanCursor? + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return ScoredValueScanCursor scan cursor. + * + **/ + suspend fun zscan(key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): ScoredValueScanCursor? + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return ScoredValueScanCursor scan cursor. + * + **/ + suspend fun zscan(key: K?, scanCursor: ScanCursor?): ScoredValueScanCursor? + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?): StreamScanCursor? + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?, scanArgs: ScanArgs?): StreamScanCursor? + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?, scanCursor: ScanCursor?): StreamScanCursor? + + /** + * Get the score associated with the given member in a sorted set. + * + * @param key the key. + * @param member the member type: value. + * @return Double bulk-string-reply the score of {@code member} (a double precision floating point number), represented as + * string. + * + **/ + suspend fun zscore(key: K?, member: V?): Double? + + /** + * Add multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination destination key. + * @param keys source keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + suspend fun zunionstore(destination: K?, vararg keys: K?): Long? + + /** + * Add multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination the destination. + * @param storeArgs the storeArgs. + * @param keys the keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + suspend fun zunionstore(destination: K?, storeArgs: ZStoreArgs?, vararg keys: K?): Long? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStreamSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStreamSuspendableCommands.kt new file mode 100644 index 0000000000..5cc4bc8c15 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStreamSuspendableCommands.kt @@ -0,0 +1,369 @@ +/* + * Copyright 2018-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.Consumer +import io.lettuce.core.Limit +import io.lettuce.core.Range +import io.lettuce.core.StreamMessage +import io.lettuce.core.XAddArgs +import io.lettuce.core.XGroupCreateArgs +import io.lettuce.core.XReadArgs +import io.lettuce.core.XClaimArgs +import io.lettuce.core.XReadArgs.StreamOffset +import io.lettuce.core.models.stream.PendingMessage +import io.lettuce.core.models.stream.PendingMessages + + +/** + * Coroutine executed commands for Streams. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 5.1 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisStreamSuspendableCommands { + + /** + * Acknowledge one or more messages as processed. + * + * @param key the stream key. + * @param group name of the consumer group. + * @param messageIds message Id's to acknowledge. + * @return simple-reply the lenght of acknowledged messages. + * + **/ + suspend fun xack(key: K?, group: K?, vararg messageIds: String?): Long? + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param body message body. + * @return simple-reply the message Id. + * + **/ + suspend fun xadd(key: K?, body: Map?): String? + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param args + * @param body message body. + * @return simple-reply the message Id. + * + **/ + suspend fun xadd(key: K?, args: XAddArgs?, body: Map?): String? + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param keysAndValues message body. + * @return simple-reply the message Id. + * + **/ + suspend fun xadd(key: K?, vararg keysAndValues: Any?): String? + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param args + * @param keysAndValues message body. + * @return simple-reply the message Id. + * + **/ + suspend fun xadd(key: K?, args: XAddArgs?, vararg keysAndValues: Any?): String? + + /** + * Gets ownership of one or multiple messages in the Pending Entries List of a given stream consumer group. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @param minIdleTime + * @param messageIds message Id's to claim. + * @return simple-reply the {@link StreamMessage}. + * + **/ + suspend fun xclaim(key: K?, consumer: Consumer?, minIdleTime: Long, vararg messageIds: String?): List>? + + /** + * Gets ownership of one or multiple messages in the Pending Entries List of a given stream consumer group. + *

+ * Note that setting the {@code JUSTID} flag (calling this method with {@link XClaimArgs#justid()}) suppresses the message + * bode and {@link StreamMessage#getBody()} is {@code null}. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @param args + * @param messageIds message Id's to claim. + * @return simple-reply the {@link StreamMessage}. + * + **/ + suspend fun xclaim(key: K?, consumer: Consumer?, args: XClaimArgs?, vararg messageIds: String?): List>? + + /** + * Removes the specified entries from the stream. Returns the number of items deleted, that may be different from the number + * of IDs passed in case certain IDs do not exist. + * + * @param key the stream key. + * @param messageIds stream message Id's. + * @return simple-reply number of removed entries. + * + **/ + suspend fun xdel(key: K?, vararg messageIds: String?): Long? + + /** + * Create a consumer group. + * + * @param streamOffset name of the stream containing the offset to set. + * @param group name of the consumer group. + * @return simple-reply {@code true} if successful. + * + **/ + suspend fun xgroupCreate(streamOffset: StreamOffset?, group: K?): String? + + /** + * Create a consumer group. + * + * @param streamOffset name of the stream containing the offset to set. + * @param group name of the consumer group. + * @param args + * @return simple-reply {@code true} if successful. + * @since 5.2 + * + **/ + suspend fun xgroupCreate(streamOffset: StreamOffset?, group: K?, args: XGroupCreateArgs?): String? + + /** + * Delete a consumer from a consumer group. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @return Long integer-reply number of pending messages. + * + **/ + suspend fun xgroupDelconsumer(key: K?, consumer: Consumer?): Long? + + /** + * Destroy a consumer group. + * + * @param key the stream key. + * @param group name of the consumer group. + * @return simple-reply {@code true} if successful. + * + **/ + suspend fun xgroupDestroy(key: K?, group: K?): Boolean? + + /** + * Set the current {@code group} id. + * + * @param streamOffset name of the stream containing the offset to set. + * @param group name of the consumer group. + * @return simple-reply OK. + * + **/ + suspend fun xgroupSetid(streamOffset: StreamOffset?, group: K?): String? + + /** + * Retrieve information about the stream at {@code key}. + * + * @param key the stream key. + * @return List array-reply. + * @since 5.2 + * + **/ + suspend fun xinfoStream(key: K?): List? + + /** + * Retrieve information about the stream consumer groups at {@code key}. + * + * @param key the stream key. + * @return List array-reply. + * @since 5.2 + * + **/ + suspend fun xinfoGroups(key: K?): List? + + /** + * Retrieve information about consumer groups of group {@code group} and stream at {@code key}. + * + * @param key the stream key. + * @param group name of the consumer group. + * @return List array-reply. + * @since 5.2 + * + **/ + suspend fun xinfoConsumers(key: K?, group: K?): List? + + /** + * Get the length of a steam. + * + * @param key the stream key. + * @return simple-reply the lenght of the stream. + * + **/ + suspend fun xlen(key: K?): Long? + + /** + * Read pending messages from a stream for a {@code group}. + * + * @param key the stream key. + * @param group name of the consumer group. + * @return List array-reply list pending entries. + * + **/ + suspend fun xpending(key: K?, group: K?): PendingMessages? + + /** + * Read pending messages from a stream within a specific {@link Range}. + * + * @param key the stream key. + * @param group name of the consumer group. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xpending(key: K?, group: K?, range: Range?, limit: Limit?): List? + + /** + * Read pending messages from a stream within a specific {@link Range}. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xpending(key: K?, consumer: Consumer?, range: Range?, limit: Limit?): List? + + /** + * Read messages from a stream within a specific {@link Range}. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xrange(key: K?, range: Range?): List>? + + /** + * Read messages from a stream within a specific {@link Range} applying a {@link Limit}. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xrange(key: K?, range: Range?, limit: Limit?): List>? + + /** + * Read messages from one or more {@link StreamOffset}s. + * + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xread(vararg streams: StreamOffset?): List>? + + /** + * Read messages from one or more {@link StreamOffset}s. + * + * @param args read arguments. + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xread(args: XReadArgs?, vararg streams: StreamOffset?): List>? + + /** + * Read messages from one or more {@link StreamOffset}s using a consumer group. + * + * @param consumer consumer/group. + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xreadgroup(consumer: Consumer?, vararg streams: StreamOffset?): List>? + + /** + * Read messages from one or more {@link StreamOffset}s using a consumer group. + * + * @param consumer consumer/group. + * @param args read arguments. + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xreadgroup(consumer: Consumer?, args: XReadArgs?, vararg streams: StreamOffset?): List>? + + /** + * Read messages from a stream within a specific {@link Range} in reverse order. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xrevrange(key: K?, range: Range?): List>? + + /** + * Read messages from a stream within a specific {@link Range} applying a {@link Limit} in reverse order. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + suspend fun xrevrange(key: K?, range: Range?, limit: Limit?): List>? + + /** + * Trims the stream to {@code count} elements. + * + * @param key the stream key. + * @param count length of the stream. + * @return simple-reply number of removed entries. + * + **/ + suspend fun xtrim(key: K?, count: Long): Long? + + /** + * Trims the stream to {@code count} elements. + * + * @param key the stream key. + * @param approximateTrimming @code true} to trim approximately using the {@code ~} flag. + * @param count length of the stream. + * @return simple-reply number of removed entries. + * + **/ + suspend fun xtrim(key: K?, approximateTrimming: Boolean, count: Long): Long? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStringSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStringSuspendableCommands.kt new file mode 100644 index 0000000000..dc08163dc5 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisStringSuspendableCommands.kt @@ -0,0 +1,429 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.BitFieldArgs +import io.lettuce.core.KeyValue +import io.lettuce.core.SetArgs +import io.lettuce.core.StrAlgoArgs +import io.lettuce.core.StringMatchResult +import io.lettuce.core.output.KeyValueStreamingChannel + + +/** + * Coroutine executed commands for Strings. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisStringSuspendableCommands { + + /** + * Append a value to a key. + * + * @param key the key. + * @param value the value. + * @return Long integer-reply the length of the string after the append operation. + * + **/ + suspend fun append(key: K?, value: V?): Long? + + /** + * Count set bits in a string. + * + * @param key the key. + * @return Long integer-reply The number of bits set to 1. + * + **/ + suspend fun bitcount(key: K?): Long? + + /** + * Count set bits in a string. + * + * @param key the key. + * @param start the start. + * @param end the end. + * @return Long integer-reply The number of bits set to 1. + * + **/ + suspend fun bitcount(key: K?, start: Long, end: Long): Long? + + /** + * Execute {@code BITFIELD} with its subcommands. + * + * @param key the key. + * @param bitFieldArgs the args containing subcommands, must not be {@code null}. + * @return Long bulk-reply the results from the bitfield commands. + * + **/ + suspend fun bitfield(key: K?, bitFieldArgs: BitFieldArgs?): List? + + /** + * Find first bit set or clear in a string. + * + * @param key the key. + * @param state the state. + * @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request. + * + * If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is + * returned. + * + * If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns + * the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the + * command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1. + * + * Basically the function consider the right of the string as padded with zeros if you look for clear bits and + * specify no range or the start argument only. + * + **/ + suspend fun bitpos(key: K?, state: Boolean): Long? + + /** + * Find first bit set or clear in a string. + * + * @param key the key. + * @param state the bit type: long. + * @param start the start type: long. + * @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request. + * + * If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is + * returned. + * + * If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns + * the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the + * command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1. + * + * Basically the function consider the right of the string as padded with zeros if you look for clear bits and + * specify no range or the start argument only. + * @since 5.0.1 + * + **/ + suspend fun bitpos(key: K?, state: Boolean, start: Long): Long? + + /** + * Find first bit set or clear in a string. + * + * @param key the key. + * @param state the bit type: long. + * @param start the start type: long. + * @param end the end type: long. + * @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request. + * + * If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is + * returned. + * + * If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns + * the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the + * command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1. + * + * Basically the function consider the right of the string as padded with zeros if you look for clear bits and + * specify no range or the start argument only. + * + * However this behavior changes if you are looking for clear bits and specify a range with both + * start and end. If no clear bit is found in the specified range, the function + * returns -1 as the user specified a clear range and there are no 0 bits in that range. + * + **/ + suspend fun bitpos(key: K?, state: Boolean, start: Long, end: Long): Long? + + /** + * Perform bitwise AND between strings. + * + * @param destination result key of the operation. + * @param keys operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + suspend fun bitopAnd(destination: K?, vararg keys: K?): Long? + + /** + * Perform bitwise NOT between strings. + * + * @param destination result key of the operation. + * @param source operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + suspend fun bitopNot(destination: K?, source: K?): Long? + + /** + * Perform bitwise OR between strings. + * + * @param destination result key of the operation. + * @param keys operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + suspend fun bitopOr(destination: K?, vararg keys: K?): Long? + + /** + * Perform bitwise XOR between strings. + * + * @param destination result key of the operation. + * @param keys operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + suspend fun bitopXor(destination: K?, vararg keys: K?): Long? + + /** + * Decrement the integer value of a key by one. + * + * @param key the key. + * @return Long integer-reply the value of {@code key} after the decrement. + * + **/ + suspend fun decr(key: K?): Long? + + /** + * Decrement the integer value of a key by the given number. + * + * @param key the key. + * @param amount the decrement type: long. + * @return Long integer-reply the value of {@code key} after the decrement. + * + **/ + suspend fun decrby(key: K?, amount: Long): Long? + + /** + * Get the value of a key. + * + * @param key the key. + * @return V bulk-string-reply the value of {@code key}, or {@code null} when {@code key} does not exist. + * + **/ + suspend fun get(key: K?): V? + + /** + * Returns the bit value at offset in the string value stored at key. + * + * @param key the key. + * @param offset the offset type: long. + * @return Long integer-reply the bit value stored at offset. + * + **/ + suspend fun getbit(key: K?, offset: Long): Long? + + /** + * Get a substring of the string stored at a key. + * + * @param key the key. + * @param start the start type: long. + * @param end the end type: long. + * @return V bulk-string-reply. + * + **/ + suspend fun getrange(key: K?, start: Long, end: Long): V? + + /** + * Set the string value of a key and return its old value. + * + * @param key the key. + * @param value the value. + * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. + * + **/ + suspend fun getset(key: K?, value: V?): V? + + /** + * Increment the integer value of a key by one. + * + * @param key the key. + * @return Long integer-reply the value of {@code key} after the increment. + * + **/ + suspend fun incr(key: K?): Long? + + /** + * Increment the integer value of a key by the given amount. + * + * @param key the key. + * @param amount the increment type: long. + * @return Long integer-reply the value of {@code key} after the increment. + * + **/ + suspend fun incrby(key: K?, amount: Long): Long? + + /** + * Increment the float value of a key by the given amount. + * + * @param key the key. + * @param amount the increment type: double. + * @return Double bulk-string-reply the value of {@code key} after the increment. + * + **/ + suspend fun incrbyfloat(key: K?, amount: Double): Double? + + /** + * Get the values of all the given keys. + * + * @param keys the key. + * @return List array-reply list of values at the specified keys. + * + **/ + suspend fun mget(vararg keys: K?): List>? + + /** + * Stream over the values of all the given keys. + * + * @param channel the channel. + * @param keys the keys. + * @return Long array-reply list of values at the specified keys. + * + **/ + suspend fun mget(channel: KeyValueStreamingChannel?, vararg keys: K?): Long? + + /** + * Set multiple keys to multiple values. + * + * @param map the null. + * @return String simple-string-reply always {@code OK} since {@code MSET} can't fail. + * + **/ + suspend fun mset(map: Map?): String? + + /** + * Set multiple keys to multiple values, only if none of the keys exist. + * + * @param map the null. + * @return Boolean integer-reply specifically: + * + * {@code 1} if the all the keys were set. {@code 0} if no key was set (at least one key already existed). + * + **/ + suspend fun msetnx(map: Map?): Boolean? + + /** + * Set the string value of a key. + * + * @param key the key. + * @param value the value. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. + * + **/ + suspend fun set(key: K?, value: V?): String? + + /** + * Set the string value of a key. + * + * @param key the key. + * @param value the value. + * @param setArgs the setArgs. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. + * + **/ + suspend fun set(key: K?, value: V?, setArgs: SetArgs?): String? + + /** + * Sets or clears the bit at offset in the string value stored at key. + * + * @param key the key. + * @param offset the offset type: long. + * @param value the value type: string. + * @return Long integer-reply the original bit value stored at offset. + * + **/ + suspend fun setbit(key: K?, offset: Long, value: Int): Long? + + /** + * Set the value and expiration of a key. + * + * @param key the key. + * @param seconds the seconds type: long. + * @param value the value. + * @return String simple-string-reply. + * + **/ + suspend fun setex(key: K?, seconds: Long, value: V?): String? + + /** + * Set the value and expiration in milliseconds of a key. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param value the value. + * @return String simple-string-reply. + * + **/ + suspend fun psetex(key: K?, milliseconds: Long, value: V?): String? + + /** + * Set the value of a key, only if the key does not exist. + * + * @param key the key. + * @param value the value. + * @return Boolean integer-reply specifically: + * + * {@code 1} if the key was set {@code 0} if the key was not set. + * + **/ + suspend fun setnx(key: K?, value: V?): Boolean? + + /** + * Overwrite part of a string at key starting at the specified offset. + * + * @param key the key. + * @param offset the offset type: long. + * @param value the value. + * @return Long integer-reply the length of the string after it was modified by the command. + * + **/ + suspend fun setrange(key: K?, offset: Long, value: V?): Long? + + /** + * The STRALGO command implements complex algorithms that operate on strings. This method uses the LCS algorithm (longest + * common substring). + * + *
    + *
  • Without modifiers the string representing the longest common substring is returned.
  • + *
  • When {@link StrAlgoArgs#justLen() LEN} is given the command returns the length of the longest common substring.
  • + *
  • When {@link StrAlgoArgs#withIdx() IDX} is given the command returns an array with the LCS length and all the ranges + * in both the strings, start and end offset for each string, where there are matches. When + * {@link StrAlgoArgs#withMatchLen() WITHMATCHLEN} is given each array representing a match will also have the length of the + * match.
  • + *
+ * + * @param strAlgoArgs command arguments. + * @return StringMatchResult. + * @since 6.0 + * + **/ + suspend fun stralgoLcs(strAlgoArgs: StrAlgoArgs?): StringMatchResult? + + /** + * Get the length of the value stored in a key. + * + * @param key the key. + * @return Long integer-reply the length of the string at {@code key}, or {@code 0} when {@code key} does not exist. + * + **/ + suspend fun strlen(key: K?): Long? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSuspendableCommands.kt new file mode 100644 index 0000000000..037591dcfc --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSuspendableCommands.kt @@ -0,0 +1,85 @@ +/* + * Copyright 2011-2020 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 io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.api.StatefulRedisConnection + +/** + * A complete coroutine and thread-safe Redis API with 400+ Methods. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisSuspendableCommands : + BaseRedisSuspendableCommands, + RedisGeoSuspendableCommands, + RedisHashSuspendableCommands, + RedisHLLSuspendableCommands, + RedisKeySuspendableCommands, + RedisListSuspendableCommands, + RedisScriptingSuspendableCommands, + RedisServerSuspendableCommands, + RedisSetSuspendableCommands, + RedisSortedSetSuspendableCommands, + RedisStreamSuspendableCommands, + RedisStringSuspendableCommands, + RedisTransactionalSuspendableCommands { + + /** + * Authenticate to the server. + * + * @param password the password + * @return String simple-string-reply + */ + suspend fun auth(password: CharSequence?): String? + + /** + * Authenticate to the server with username and password. Requires Redis 6 or newer. + * + * @param username the username + * @param password the password + * @return String simple-string-reply + * @since 6.0 + */ + suspend fun auth(username: String?, password: CharSequence?): String? + + /** + * Change the selected database for the current connection. + * + * @param db the database number + * @return String simple-string-reply + */ + suspend fun select(db: Int): String? + + /** + * Swap two Redis databases, so that immediately all the clients connected to a given DB will see the data of the other DB, + * and the other way around + * + * @param db1 the first database number + * @param db2 the second database number + * @return String simple-string-reply + */ + suspend fun swapdb(db1: Int, db2: Int): String? + + /** + * @return the underlying connection. + */ + val statefulConnection: StatefulRedisConnection +} \ No newline at end of file diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSuspendableCommandsExtensions.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSuspendableCommandsExtensions.kt new file mode 100644 index 0000000000..9eb946f5e9 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSuspendableCommandsExtensions.kt @@ -0,0 +1,21 @@ +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.TransactionResult + +/** + * Allows to create transaction DSL block with [RedisSuspendableCommands]. + * + * @author Mikhael Sokolov + * @since 6.0 + */ +@ExperimentalLettuceCoroutinesApi +suspend inline fun RedisSuspendableCommands.multi(action: RedisSuspendableCommands.() -> Unit): TransactionResult? { + multi() + runCatching { + action.invoke(this) + }.onFailure { + discard() + } + return exec() +} \ No newline at end of file diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisTransactionalSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisTransactionalSuspendableCommands.kt new file mode 100644 index 0000000000..d0d257ad35 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisTransactionalSuspendableCommands.kt @@ -0,0 +1,84 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.TransactionResult + + +/** + * Coroutine executed commands for Transactions. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisTransactionalSuspendableCommands { + + /** + * Discard all commands issued after MULTI. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + suspend fun discard(): String? + + /** + * Execute all commands issued after MULTI. + * + * @return List array-reply each element being the reply to each of the commands in the atomic transaction. + * + * When using {@code WATCH}, {@code EXEC} can return a {@link TransactionResult#wasDiscarded discarded + * TransactionResult}. + * @see TransactionResult#wasDiscarded + * + **/ + suspend fun exec(): TransactionResult? + + /** + * Mark the start of a transaction block. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + suspend fun multi(): String? + + /** + * Watch the given keys to determine execution of the MULTI/EXEC block. + * + * @param keys the key. + * @return String simple-string-reply always {@code OK}. + * + **/ + suspend fun watch(vararg keys: K?): String? + + /** + * Forget about all watched keys. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + suspend fun unwatch(): String? + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/BaseRedisSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/BaseRedisSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..fa0b0e345c --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/BaseRedisSuspendableAsyncCommands.kt @@ -0,0 +1,206 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.protocol.CommandArgs +import io.lettuce.core.protocol.ProtocolKeyword +import io.lettuce.core.output.CommandOutput + + +/** + * Coroutine executed commands (based on async commands) for basic commands. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class BaseRedisSuspendableAsyncCommands(private val ops: BaseRedisAsyncCommands) : BaseRedisSuspendableCommands { + + /** + * Post a message to a channel. + * + * @param channel the channel type: key. + * @param message the message type: value. + * @return Long integer-reply the number of clients that received the message. + * + **/ + override suspend fun publish(channel: K?, message: V?): Long? = ops.publish(channel, message).await() + + /** + * Lists the currently *active channels*. + * + * @return List array-reply a list of active channels, optionally matching the specified pattern. + * + **/ + override suspend fun pubsubChannels(): List? = ops.pubsubChannels().await() + + /** + * Lists the currently *active channels*. + * + * @param channel the key. + * @return List array-reply a list of active channels, optionally matching the specified pattern. + * + **/ + override suspend fun pubsubChannels(channel: K?): List? = ops.pubsubChannels(channel).await() + + /** + * Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels. + * + * @param channels channel keys. + * @return array-reply a list of channels and number of subscribers for every channel. + * + **/ + override suspend fun pubsubNumsub(vararg channels: K?): Map? = ops.pubsubNumsub(*channels).await() + + /** + * Returns the number of subscriptions to patterns. + * + * @return Long integer-reply the number of patterns all the clients are subscribed to. + * + **/ + override suspend fun pubsubNumpat(): Long? = ops.pubsubNumpat().await() + + /** + * Echo the given string. + * + * @param msg the message type: value. + * @return V bulk-string-reply. + * + **/ + override suspend fun echo(msg: V?): V? = ops.echo(msg).await() + + /** + * Return the role of the instance in the context of replication. + * + * @return List array-reply where the first element is one of master, slave, sentinel and the additional + * elements are role-specific. + * + **/ + override suspend fun role(): List? = ops.role().await() + + /** + * Ping the server. + * + * @return String simple-string-reply. + * + **/ + override suspend fun ping(): String? = ops.ping().await() + + /** + * Switch connection to Read-Only mode when connecting to a cluster. + * + * @return String simple-string-reply. + * + **/ + override suspend fun readOnly(): String? = ops.readOnly().await() + + /** + * Switch connection to Read-Write mode (default) when connecting to a cluster. + * + * @return String simple-string-reply. + * + **/ + override suspend fun readWrite(): String? = ops.readWrite().await() + + /** + * Instructs Redis to disconnect the connection. Note that if auto-reconnect is enabled then Lettuce will auto-reconnect if + * the connection was disconnected. Use {@link io.lettuce.core.api.StatefulConnection#close} to close connections and + * release resources. + * + * @return String simple-string-reply always OK. + * + **/ + override suspend fun quit(): String? = ops.quit().await() + + /** + * Wait for replication. + * + * @param replicas minimum number of replicas. + * @param timeout timeout in milliseconds. + * @return number of replicas. + * + **/ + override suspend fun waitForReplication(replicas: Int, timeout: Long): Long? = ops.waitForReplication(replicas, timeout).await() + + /** + * Dispatch a command to the Redis Server. Please note the command output type must fit to the command response. + * + * @param type the command, must not be {@code null}. + * @param output the command output, must not be {@code null}. + * @param response type. + * @return the command response. + * + **/ + override suspend fun dispatch(type: ProtocolKeyword?, output: CommandOutput?): T? = ops.dispatch(type, output).await() + + /** + * Dispatch a command to the Redis Server. Please note the command output type must fit to the command response. + * + * @param type the command, must not be {@code null}. + * @param output the command output, must not be {@code null}. + * @param args the command arguments, must not be {@code null}. + * @param response type. + * @return the command response. + * + **/ + override suspend fun dispatch(type: ProtocolKeyword?, output: CommandOutput?, args: CommandArgs?): T? = ops.dispatch(type, output, args).await() + + /** + * + * @return @code true} if the connection is open (connected and not closed). + * + **/ + override suspend fun isOpen(): Boolean = ops.isOpen() + + /** + * Reset the command state. Queued commands will be canceled and the internal state will be reset. This is useful when the + * internal state machine gets out of sync with the connection. + * + **/ + override suspend fun reset(): Unit? = ops.reset() + + /** + * Disable or enable auto-flush behavior. Default is {@code true}. If autoFlushCommands is disabled, multiple commands can + * be issued without writing them actually to the transport. Commands are buffered until a {@link #flushCommands()} is + * issued. After calling {@link #flushCommands()} commands are sent to the transport and executed by Redis. + * + * @param autoFlush state of autoFlush. + * + **/ + override suspend fun setAutoFlushCommands(autoFlush: Boolean): Unit? = ops.setAutoFlushCommands(autoFlush) + + /** + * Flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to + * achieve batching. No-op if channel is not connected. + * + **/ + override suspend fun flushCommands(): Unit? = ops.flushCommands() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisGeoSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisGeoSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..d24cca8574 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisGeoSuspendableAsyncCommands.kt @@ -0,0 +1,185 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.* + + +/** + * Coroutine executed commands (based on async commands) for the Geo-API. + * + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisGeoSuspendableAsyncCommands(private val ops: RedisGeoAsyncCommands) : RedisGeoSuspendableCommands { + + /** + * Single geo add. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param member the member to add. + * @return Long integer-reply the number of elements that were added to the set. + * + **/ + override suspend fun geoadd(key: K?, longitude: Double, latitude: Double, member: V?): Long? = ops.geoadd(key, longitude, latitude, member).await() + + /** + * Multi geo add. + * + * @param key the key of the geo set. + * @param lngLatMember triplets of double longitude, double latitude and V member. + * @return Long integer-reply the number of elements that were added to the set. + * + **/ + override suspend fun geoadd(key: K?, vararg lngLatMember: Any?): Long? = ops.geoadd(key, *lngLatMember).await() + + /** + * Retrieve Geohash strings representing the position of one or more elements in a sorted set value representing a + * geospatial index. + * + * @param key the key of the geo set. + * @param members the members. + * @return bulk reply Geohash strings in the order of {@code members}. Returns {@code null} if a member is not found. + * + **/ + override suspend fun geohash(key: K?, vararg members: V?): List>? = ops.geohash(key, *members).await() + + /** + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param distance radius distance. + * @param unit distance unit. + * @return bulk reply. + * + **/ + override suspend fun georadius(key: K?, longitude: Double, latitude: Double, distance: Double, unit: GeoArgs.Unit?): Set? = ops.georadius(key, longitude, latitude, distance, unit).await() + + /** + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param distance radius distance. + * @param unit distance unit. + * @param geoArgs args to control the result. + * @return nested multi-bulk reply. The {@link GeoWithin} contains only fields which were requested by {@link GeoArgs}. + * + **/ + override suspend fun georadius(key: K?, longitude: Double, latitude: Double, distance: Double, unit: GeoArgs.Unit?, geoArgs: GeoArgs?): List>? = ops.georadius(key, longitude, latitude, distance, unit, geoArgs).await() + + /** + * Perform a {@link #georadius(Object, double, double, double, GeoArgs.Unit, GeoArgs)} query and store the results in a + * sorted set. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param distance radius distance. + * @param unit distance unit. + * @param geoRadiusStoreArgs args to store either the resulting elements with their distance or the resulting elements with + * their locations a sorted set. + * @return Long integer-reply the number of elements in the result. + * + **/ + override suspend fun georadius(key: K?, longitude: Double, latitude: Double, distance: Double, unit: GeoArgs.Unit?, geoRadiusStoreArgs: GeoRadiusStoreArgs?): Long? = ops.georadius(key, longitude, latitude, distance, unit, geoRadiusStoreArgs).await() + + /** + * Retrieve members selected by distance with the center of {@code member}. The member itself is always contained in the + * results. + * + * @param key the key of the geo set. + * @param member reference member. + * @param distance radius distance. + * @param unit distance unit. + * @return set of members. + * + **/ + override suspend fun georadiusbymember(key: K?, member: V?, distance: Double, unit: GeoArgs.Unit?): Set? = ops.georadiusbymember(key, member, distance, unit).await() + + /** + * Retrieve members selected by distance with the center of {@code member}. The member itself is always contained in the + * results. + * + * @param key the key of the geo set. + * @param member reference member. + * @param distance radius distance. + * @param unit distance unit. + * @param geoArgs args to control the result. + * @return nested multi-bulk reply. The {@link GeoWithin} contains only fields which were requested by {@link GeoArgs}. + * + **/ + override suspend fun georadiusbymember(key: K?, member: V?, distance: Double, unit: GeoArgs.Unit?, geoArgs: GeoArgs?): List>? = ops.georadiusbymember(key, member, distance, unit, geoArgs).await() + + /** + * Perform a {@link #georadiusbymember(Object, Object, double, GeoArgs.Unit, GeoArgs)} query and store the results in a + * sorted set. + * + * @param key the key of the geo set. + * @param member reference member. + * @param distance radius distance. + * @param unit distance unit. + * @param geoRadiusStoreArgs args to store either the resulting elements with their distance or the resulting elements with + * their locations a sorted set. + * @return Long integer-reply the number of elements in the result. + * + **/ + override suspend fun georadiusbymember(key: K?, member: V?, distance: Double, unit: GeoArgs.Unit?, geoRadiusStoreArgs: GeoRadiusStoreArgs?): Long? = ops.georadiusbymember(key, member, distance, unit, geoRadiusStoreArgs).await() + + /** + * Get geo coordinates for the {@code members}. + * + * @param key the key of the geo set. + * @param members the members. + * @return a list of {@link GeoCoordinates}s representing the x,y position of each element specified in the arguments. For + * missing elements {@code null} is returned. + * + **/ + override suspend fun geopos(key: K?, vararg members: V?): List? = ops.geopos(key, *members).await() + + /** + * Retrieve distance between points {@code from} and {@code to}. If one or more elements are missing {@code null} is + * returned. Default in meters by, otherwise according to {@code unit} + * + * @param key the key of the geo set. + * @param from from member. + * @param to to member. + * @param unit distance unit. + * @return distance between points {@code from} and {@code to}. If one or more elements are missing {@code null} is + * returned. + * + **/ + override suspend fun geodist(key: K?, from: V?, to: V?, unit: GeoArgs.Unit?): Double? = ops.geodist(key, from, to, unit).await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisHLLSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisHLLSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..c575d5c406 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisHLLSuspendableAsyncCommands.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi + + +/** + * Coroutine executed commands (based on async commands) for HyperLogLog (PF* commands). + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisHLLSuspendableAsyncCommands(private val ops: RedisHLLAsyncCommands) : RedisHLLSuspendableCommands { + + /** + * Adds the specified elements to the specified HyperLogLog. + * + * @param key the key. + * @param values the values. + * @return Long integer-reply specifically: + * + * 1 if at least 1 HyperLogLog internal register was altered. 0 otherwise. + * + **/ + override suspend fun pfadd(key: K?, vararg values: V?): Long? = ops.pfadd(key, *values).await() + + /** + * Merge N different HyperLogLogs into a single one. + * + * @param destkey the destination key. + * @param sourcekeys the source key. + * @return String simple-string-reply The command just returns {@code OK}. + * + **/ + override suspend fun pfmerge(destkey: K?, vararg sourcekeys: K?): String? = ops.pfmerge(destkey, *sourcekeys).await() + + /** + * Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s). + * + * @param keys the keys. + * @return Long integer-reply specifically: + * + * The approximated number of unique elements observed via {@code PFADD}. + * + **/ + override suspend fun pfcount(vararg keys: K?): Long? = ops.pfcount(*keys).await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisHashSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisHashSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..a92f075a2d --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisHashSuspendableAsyncCommands.kt @@ -0,0 +1,336 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.* +import io.lettuce.core.output.KeyStreamingChannel +import io.lettuce.core.output.KeyValueStreamingChannel +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on async commands) for Hashes (Key-Value pairs). + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisHashSuspendableAsyncCommands(private val ops: RedisHashAsyncCommands) : RedisHashSuspendableCommands { + + /** + * Delete one or more hash fields. + * + * @param key the key. + * @param fields the field type: key. + * @return Long integer-reply the number of fields that were removed from the hash, not including specified but non existing + * fields. + * + **/ + override suspend fun hdel(key: K?, vararg fields: K?): Long? = ops.hdel(key, *fields).await() + + /** + * Determine if a hash field exists. + * + * @param key the key. + * @param field the field type: key. + * @return Boolean integer-reply specifically: + * + * {@code true} if the hash contains {@code field}. {@code false} if the hash does not contain {@code field}, or + * {@code key} does not exist. + * + **/ + override suspend fun hexists(key: K?, field: K?): Boolean? = ops.hexists(key, field).await() + + /** + * Get the value of a hash field. + * + * @param key the key. + * @param field the field type: key. + * @return V bulk-string-reply the value associated with {@code field}, or {@code null} when {@code field} is not present in + * the hash or {@code key} does not exist. + * + **/ + override suspend fun hget(key: K?, field: K?): V? = ops.hget(key, field).await() + + /** + * Increment the integer value of a hash field by the given number. + * + * @param key the key. + * @param field the field type: key. + * @param amount the increment type: long. + * @return Long integer-reply the value at {@code field} after the increment operation. + * + **/ + override suspend fun hincrby(key: K?, field: K?, amount: Long): Long? = ops.hincrby(key, field, amount).await() + + /** + * Increment the float value of a hash field by the given amount. + * + * @param key the key. + * @param field the field type: key. + * @param amount the increment type: double. + * @return Double bulk-string-reply the value of {@code field} after the increment. + * + **/ + override suspend fun hincrbyfloat(key: K?, field: K?, amount: Double): Double? = ops.hincrbyfloat(key, field, amount).await() + + /** + * Get all the fields and values in a hash. + * + * @param key the key. + * @return Map array-reply list of fields and their values stored in the hash, or an empty list when {@code key} + * does not exist. + * + **/ + override suspend fun hgetall(key: K?): Map? = ops.hgetall(key).await() + + /** + * Stream over all the fields and values in a hash. + * + * @param channel the channel. + * @param key the key. + * @return Long count of the keys. + * + **/ + override suspend fun hgetall(channel: KeyValueStreamingChannel?, key: K?): Long? = ops.hgetall(channel, key).await() + + /** + * Get all the fields in a hash. + * + * @param key the key. + * @return List array-reply list of fields in the hash, or an empty list when {@code key} does not exist. + * + **/ + override suspend fun hkeys(key: K?): List? = ops.hkeys(key).await() + + /** + * Stream over all the fields in a hash. + * + * @param channel the channel. + * @param key the key. + * @return Long count of the keys. + * + **/ + override suspend fun hkeys(channel: KeyStreamingChannel?, key: K?): Long? = ops.hkeys(channel, key).await() + + /** + * Get the number of fields in a hash. + * + * @param key the key. + * @return Long integer-reply number of fields in the hash, or {@code 0} when {@code key} does not exist. + * + **/ + override suspend fun hlen(key: K?): Long? = ops.hlen(key).await() + + /** + * Get the values of all the given hash fields. + * + * @param key the key. + * @param fields the field type: key. + * @return List array-reply list of values associated with the given fields, in the same. + * + **/ + override suspend fun hmget(key: K?, vararg fields: K?): List>? = ops.hmget(key, *fields).await() + + /** + * Stream over the values of all the given hash fields. + * + * @param channel the channel. + * @param key the key. + * @param fields the fields. + * @return Long count of the keys. + * + **/ + override suspend fun hmget(channel: KeyValueStreamingChannel?, key: K?, vararg fields: K?): Long? = ops.hmget(channel, key, *fields).await() + + /** + * Set multiple hash fields to multiple values. + * + * @param key the key. + * @param map the null. + * @return String simple-string-reply. + * + **/ + override suspend fun hmset(key: K?, map: Map?): String? = ops.hmset(key, map).await() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @return MapScanCursor map scan cursor. + * + **/ + override suspend fun hscan(key: K?): MapScanCursor? = ops.hscan(key).await() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @param scanArgs scan arguments. + * @return MapScanCursor map scan cursor. + * + **/ + override suspend fun hscan(key: K?, scanArgs: ScanArgs?): MapScanCursor? = ops.hscan(key, scanArgs).await() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return MapScanCursor map scan cursor. + * + **/ + override suspend fun hscan(key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): MapScanCursor? = ops.hscan(key, scanCursor, scanArgs).await() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return MapScanCursor map scan cursor. + * + **/ + override suspend fun hscan(key: K?, scanCursor: ScanCursor?): MapScanCursor? = ops.hscan(key, scanCursor).await() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?): StreamScanCursor? = ops.hscan(channel, key).await() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?, scanArgs: ScanArgs?): StreamScanCursor? = ops.hscan(channel, key, scanArgs).await() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? = ops.hscan(channel, key, scanCursor, scanArgs).await() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?, scanCursor: ScanCursor?): StreamScanCursor? = ops.hscan(channel, key, scanCursor).await() + + /** + * Set the string value of a hash field. + * + * @param key the key. + * @param field the field type: key. + * @param value the value. + * @return Boolean integer-reply specifically: + * + * {@code true} if {@code field} is a new field in the hash and {@code value} was set. {@code false} if + * {@code field} already exists in the hash and the value was updated. + * + **/ + override suspend fun hset(key: K?, field: K?, value: V?): Boolean? = ops.hset(key, field, value).await() + + /** + * Set multiple hash fields to multiple values. + * + * @param key the key of the hash. + * @param map the field/value pairs to update. + * @return Long integer-reply: the number of fields that were added. + * @since 5.3 + * + **/ + override suspend fun hset(key: K?, map: Map?): Long? = ops.hset(key, map).await() + + /** + * Set the value of a hash field, only if the field does not exist. + * + * @param key the key. + * @param field the field type: key. + * @param value the value. + * @return Boolean integer-reply specifically: + * + * {@code 1} if {@code field} is a new field in the hash and {@code value} was set. {@code 0} if {@code field} + * already exists in the hash and no operation was performed. + * + **/ + override suspend fun hsetnx(key: K?, field: K?, value: V?): Boolean? = ops.hsetnx(key, field, value).await() + + /** + * Get the string length of the field value in a hash. + * + * @param key the key. + * @param field the field type: key. + * @return Long integer-reply the string length of the {@code field} value, or {@code 0} when {@code field} is not present + * in the hash or {@code key} does not exist at all. + * + **/ + override suspend fun hstrlen(key: K?, field: K?): Long? = ops.hstrlen(key, field).await() + + /** + * Get all the values in a hash. + * + * @param key the key. + * @return List array-reply list of values in the hash, or an empty list when {@code key} does not exist. + * + **/ + override suspend fun hvals(key: K?): List? = ops.hvals(key).await() + + /** + * Stream over all the values in a hash. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @return Long count of the keys. + * + **/ + override suspend fun hvals(channel: ValueStreamingChannel?, key: K?): Long? = ops.hvals(channel, key).await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisKeySuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisKeySuspendableAsyncCommands.kt new file mode 100644 index 0000000000..a4d7374d33 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisKeySuspendableAsyncCommands.kt @@ -0,0 +1,471 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import java.util.Date +import io.lettuce.core.* +import io.lettuce.core.output.KeyStreamingChannel +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on async commands) for Keys (Key manipulation/querying). + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisKeySuspendableAsyncCommands(private val ops: RedisKeyAsyncCommands) : RedisKeySuspendableCommands { + + /** + * Delete one or more keys. + * + * @param keys the keys. + * @return Long integer-reply The number of keys that were removed. + * + **/ + override suspend fun del(vararg keys: K?): Long? = ops.del(*keys).await() + + /** + * Unlink one or more keys (non blocking DEL). + * + * @param keys the keys. + * @return Long integer-reply The number of keys that were removed. + * + **/ + override suspend fun unlink(vararg keys: K?): Long? = ops.unlink(*keys).await() + + /** + * Return a serialized version of the value stored at the specified key. + * + * @param key the key. + * @return byte[] bulk-string-reply the serialized value. + * + **/ + override suspend fun dump(key: K?): ByteArray? = ops.dump(key).await() + + /** + * Determine how many keys exist. + * + * @param keys the keys. + * @return Long integer-reply specifically: Number of existing keys. + * + **/ + override suspend fun exists(vararg keys: K?): Long? = ops.exists(*keys).await() + + /** + * Set a key's time to live in seconds. + * + * @param key the key. + * @param seconds the seconds type: long. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set. + * + **/ + override suspend fun expire(key: K?, seconds: Long): Boolean? = ops.expire(key, seconds).await() + + /** + * Set the expiration for a key as a UNIX timestamp. + * + * @param key the key. + * @param timestamp the timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + override suspend fun expireat(key: K?, timestamp: Date?): Boolean? = ops.expireat(key, timestamp).await() + + /** + * Set the expiration for a key as a UNIX timestamp. + * + * @param key the key. + * @param timestamp the timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + override suspend fun expireat(key: K?, timestamp: Long): Boolean? = ops.expireat(key, timestamp).await() + + /** + * Find all keys matching the given pattern. + * + * @param pattern the pattern type: patternkey (pattern). + * @return List array-reply list of keys matching {@code pattern}. + * + **/ + override suspend fun keys(pattern: K?): List? = ops.keys(pattern).await() + + /** + * Find all keys matching the given pattern. + * + * @param channel the channel. + * @param pattern the pattern. + * @return Long array-reply list of keys matching {@code pattern}. + * + **/ + override suspend fun keys(channel: KeyStreamingChannel?, pattern: K?): Long? = ops.keys(channel, pattern).await() + + /** + * Atomically transfer a key from a Redis instance to another one. + * + * @param host the host. + * @param port the port. + * @param key the key. + * @param db the database. + * @param timeout the timeout in milliseconds. + * @return String simple-string-reply The command returns OK on success. + * + **/ + override suspend fun migrate(host: String?, port: Int, key: K?, db: Int, timeout: Long): String? = ops.migrate(host, port, key, db, timeout).await() + + /** + * Atomically transfer one or more keys from a Redis instance to another one. + * + * @param host the host. + * @param port the port. + * @param db the database. + * @param timeout the timeout in milliseconds. + * @param migrateArgs migrate args that allow to configure further options. + * @return String simple-string-reply The command returns OK on success. + * + **/ + override suspend fun migrate(host: String?, port: Int, db: Int, timeout: Long, migrateArgs: MigrateArgs?): String? = ops.migrate(host, port, db, timeout, migrateArgs).await() + + /** + * Move a key to another database. + * + * @param key the key. + * @param db the db type: long. + * @return Boolean integer-reply specifically:. + * + **/ + override suspend fun move(key: K?, db: Int): Boolean? = ops.move(key, db).await() + + /** + * returns the kind of internal representation used in order to store the value associated with a key. + * + * @param key the key. + * @return String. + * + **/ + override suspend fun objectEncoding(key: K?): String? = ops.objectEncoding(key).await() + + /** + * returns the number of seconds since the object stored at the specified key is idle (not requested by read or write + * operations). + * + * @param key the key. + * @return number of seconds since the object stored at the specified key is idle. + * + **/ + override suspend fun objectIdletime(key: K?): Long? = ops.objectIdletime(key).await() + + /** + * returns the number of references of the value associated with the specified key. + * + * @param key the key. + * @return Long. + * + **/ + override suspend fun objectRefcount(key: K?): Long? = ops.objectRefcount(key).await() + + /** + * Remove the expiration from a key. + * + * @param key the key. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was removed. {@code false} if {@code key} does not exist or does not have an + * associated timeout. + * + **/ + override suspend fun persist(key: K?): Boolean? = ops.persist(key).await() + + /** + * Set a key's time to live in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @return integer-reply, specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set. + * + **/ + override suspend fun pexpire(key: K?, milliseconds: Long): Boolean? = ops.pexpire(key, milliseconds).await() + + /** + * Set the expiration for a key as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + override suspend fun pexpireat(key: K?, timestamp: Date?): Boolean? = ops.pexpireat(key, timestamp).await() + + /** + * Set the expiration for a key as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + override suspend fun pexpireat(key: K?, timestamp: Long): Boolean? = ops.pexpireat(key, timestamp).await() + + /** + * Get the time to live for a key in milliseconds. + * + * @param key the key. + * @return Long integer-reply TTL in milliseconds, or a negative value in order to signal an error (see the description + * above). + * + **/ + override suspend fun pttl(key: K?): Long? = ops.pttl(key).await() + + /** + * Return a random key from the keyspace. + * + * @return K bulk-string-reply the random key, or {@code null} when the database is empty. + * + **/ + override suspend fun randomkey(): K? = ops.randomkey().await() + + /** + * Rename a key. + * + * @param key the key. + * @param newKey the newkey type: key. + * @return String simple-string-reply. + * + **/ + override suspend fun rename(key: K?, newKey: K?): String? = ops.rename(key, newKey).await() + + /** + * Rename a key, only if the new key does not exist. + * + * @param key the key. + * @param newKey the newkey type: key. + * @return Boolean integer-reply specifically: + * + * {@code true} if {@code key} was renamed to {@code newkey}. {@code false} if {@code newkey} already exists. + * + **/ + override suspend fun renamenx(key: K?, newKey: K?): Boolean? = ops.renamenx(key, newKey).await() + + /** + * Create a key using the provided serialized value, previously obtained using DUMP. + * + * @param key the key. + * @param ttl the ttl type: long. + * @param value the serialized-value type: string. + * @return String simple-string-reply The command returns OK on success. + * + **/ + override suspend fun restore(key: K?, ttl: Long, value: ByteArray?): String? = ops.restore(key, ttl, value).await() + + /** + * Create a key using the provided serialized value, previously obtained using DUMP. + * + * @param key the key. + * @param value the serialized-value type: string. + * @param args the {@link RestoreArgs}, must not be {@code null}. + * @return String simple-string-reply The command returns OK on success. + * @since 5.1 + * + **/ + override suspend fun restore(key: K?, value: ByteArray?, args: RestoreArgs?): String? = ops.restore(key, value, args).await() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param key the key. + * @return List array-reply list of sorted elements. + * + **/ + override suspend fun sort(key: K?): List? = ops.sort(key).await() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @return Long number of values. + * + **/ + override suspend fun sort(channel: ValueStreamingChannel?, key: K?): Long? = ops.sort(channel, key).await() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param key the key. + * @param sortArgs sort arguments. + * @return List array-reply list of sorted elements. + * + **/ + override suspend fun sort(key: K?, sortArgs: SortArgs?): List? = ops.sort(key, sortArgs).await() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param sortArgs sort arguments. + * @return Long number of values. + * + **/ + override suspend fun sort(channel: ValueStreamingChannel?, key: K?, sortArgs: SortArgs?): Long? = ops.sort(channel, key, sortArgs).await() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param key the key. + * @param sortArgs sort arguments. + * @param destination the destination key to store sort results. + * @return Long number of values. + * + **/ + override suspend fun sortStore(key: K?, sortArgs: SortArgs?, destination: K?): Long? = ops.sortStore(key, sortArgs, destination).await() + + /** + * Touch one or more keys. Touch sets the last accessed time for a key. Non-exsitent keys wont get created. + * + * @param keys the keys. + * @return Long integer-reply the number of found keys. + * + **/ + override suspend fun touch(vararg keys: K?): Long? = ops.touch(*keys).await() + + /** + * Get the time to live for a key. + * + * @param key the key. + * @return Long integer-reply TTL in seconds, or a negative value in order to signal an error (see the description above). + * + **/ + override suspend fun ttl(key: K?): Long? = ops.ttl(key).await() + + /** + * Determine the type stored at key. + * + * @param key the key. + * @return String simple-string-reply type of {@code key}, or {@code none} when {@code key} does not exist. + * + **/ + override suspend fun type(key: K?): String? = ops.type(key).await() + + /** + * Incrementally iterate the keys space. + * + * @return KeyScanCursor scan cursor. + * + **/ + override suspend fun scan(): KeyScanCursor? = ops.scan().await() + + /** + * Incrementally iterate the keys space. + * + * @param scanArgs scan arguments. + * @return KeyScanCursor scan cursor. + * + **/ + override suspend fun scan(scanArgs: ScanArgs?): KeyScanCursor? = ops.scan(scanArgs).await() + + /** + * Incrementally iterate the keys space. + * + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return KeyScanCursor scan cursor. + * + **/ + override suspend fun scan(scanCursor: ScanCursor?, scanArgs: ScanArgs?): KeyScanCursor? = ops.scan(scanCursor, scanArgs).await() + + /** + * Incrementally iterate the keys space. + * + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return KeyScanCursor scan cursor. + * + **/ + override suspend fun scan(scanCursor: ScanCursor?): KeyScanCursor? = ops.scan(scanCursor).await() + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun scan(channel: KeyStreamingChannel?): StreamScanCursor? = ops.scan(channel).await() + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun scan(channel: KeyStreamingChannel?, scanArgs: ScanArgs?): StreamScanCursor? = ops.scan(channel, scanArgs).await() + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun scan(channel: KeyStreamingChannel?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? = ops.scan(channel, scanCursor, scanArgs).await() + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun scan(channel: KeyStreamingChannel?, scanCursor: ScanCursor?): StreamScanCursor? = ops.scan(channel, scanCursor).await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisListSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisListSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..b02c2a4416 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisListSuspendableAsyncCommands.kt @@ -0,0 +1,304 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.KeyValue +import io.lettuce.core.LPosArgs +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on async commands) for Lists. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisListSuspendableAsyncCommands(private val ops: RedisListAsyncCommands) : RedisListSuspendableCommands { + + /** + * Remove and get the first element in a list, or block until one is available. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue array-reply specifically: + * + * A {@code null} multi-bulk when no element could be popped and the timeout expired. A two-element multi-bulk with + * the first element being the name of the key where an element was popped and the second element being the value of + * the popped element. + * + **/ + override suspend fun blpop(timeout: Long, vararg keys: K?): KeyValue? = ops.blpop(timeout, *keys).await() + + /** + * Remove and get the last element in a list, or block until one is available. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue array-reply specifically: + * + * A {@code null} multi-bulk when no element could be popped and the timeout expired. A two-element multi-bulk with + * the first element being the name of the key where an element was popped and the second element being the value of + * the popped element. + * + **/ + override suspend fun brpop(timeout: Long, vararg keys: K?): KeyValue? = ops.brpop(timeout, *keys).await() + + /** + * Pop a value from a list, push it to another list and return it; or block until one is available. + * + * @param timeout the timeout in seconds. + * @param source the source key. + * @param destination the destination type: key. + * @return V bulk-string-reply the element being popped from {@code source} and pushed to {@code destination}. If + * {@code timeout} is reached, a. + * + **/ + override suspend fun brpoplpush(timeout: Long, source: K?, destination: K?): V? = ops.brpoplpush(timeout, source, destination).await() + + /** + * Get an element from a list by its index. + * + * @param key the key. + * @param index the index type: long. + * @return V bulk-string-reply the requested element, or {@code null} when {@code index} is out of range. + * + **/ + override suspend fun lindex(key: K?, index: Long): V? = ops.lindex(key, index).await() + + /** + * Insert an element before or after another element in a list. + * + * @param key the key. + * @param before the before. + * @param pivot the pivot. + * @param value the value. + * @return Long integer-reply the length of the list after the insert operation, or {@code -1} when the value {@code pivot} + * was not found. + * + **/ + override suspend fun linsert(key: K?, before: Boolean, pivot: V?, value: V?): Long? = ops.linsert(key, before, pivot, value).await() + + /** + * Get the length of a list. + * + * @param key the key. + * @return Long integer-reply the length of the list at {@code key}. + * + **/ + override suspend fun llen(key: K?): Long? = ops.llen(key).await() + + /** + * Remove and get the first element in a list. + * + * @param key the key. + * @return V bulk-string-reply the value of the first element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun lpop(key: K?): V? = ops.lpop(key).await() + + /** + * Return the index of matching elements inside a Redis list. By default, when no options are given, it will scan the list + * from head to tail, looking for the first match of "element". If the element is found, its index (the zero-based position + * in the list) is returned. Otherwise, if no match is found, {@code null} is returned. The returned elements indexes are + * always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is {@code 0}, + * and so forth. + * + * @param key the key. + * @param value the element to search for. + * @return V integer-reply representing the matching element, or null if there is no match. + * @since 5.3.2 + * + **/ + override suspend fun lpos(key: K?, value: V?): Long? = ops.lpos(key, value).await() + + /** + * Return the index of matching elements inside a Redis list. By default, when no options are given, it will scan the list + * from head to tail, looking for the first match of "element". If the element is found, its index (the zero-based position + * in the list) is returned. Otherwise, if no match is found, {@code null} is returned. The returned elements indexes are + * always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is {@code 0}, + * and so forth. + * + * @param key the key. + * @param value the element to search for. + * @param args command arguments to configure{@code FIRST} and {@code MAXLEN} options. + * @return V integer-reply representing the matching element, or null if there is no match. + * @since 5.3.2 + * + **/ + override suspend fun lpos(key: K?, value: V?, args: LPosArgs?): Long? = ops.lpos(key, value, args).await() + + /** + * Return the index of matching elements inside a Redis list using the {@code COUNT} option. By default, when no options are + * given, it will scan the list from head to tail, looking for the first match of "element". The returned elements indexes + * are always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is + * {@code 0}, and so forth. + * + * @param key the key. + * @param value the element to search for. + * @param count limit the number of matches. + * @return V integer-reply representing the matching elements, or empty if there is no match. + * @since 5.3.2 + * + **/ + override suspend fun lpos(key: K?, value: V?, count: Int): List? = ops.lpos(key, value, count).await() + + /** + * Return the index of matching elements inside a Redis list using the {@code COUNT} option. By default, when no options are + * given, it will scan the list from head to tail, looking for the first match of "element". The returned elements indexes + * are always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is + * {@code 0}, and so forth. + * + * @param key the key. + * @param value the element to search for. + * @param count limit the number of matches. + * @param args command arguments to configure{@code FIRST} and {@code MAXLEN} options. + * @return V integer-reply representing the matching elements, or empty if there is no match. + * @since 5.3.2 + * + **/ + override suspend fun lpos(key: K?, value: V?, count: Int, args: LPosArgs?): List? = ops.lpos(key, value, count, args).await() + + /** + * Prepend one or multiple values to a list. + * + * @param key the key. + * @param values the value. + * @return Long integer-reply the length of the list after the push operations. + * + **/ + override suspend fun lpush(key: K?, vararg values: V?): Long? = ops.lpush(key, *values).await() + + /** + * Prepend values to a list, only if the list exists. + * + * @param key the key. + * @param values the values. + * @return Long integer-reply the length of the list after the push operation. + * + **/ + override suspend fun lpushx(key: K?, vararg values: V?): Long? = ops.lpushx(key, *values).await() + + /** + * Get a range of elements from a list. + * + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun lrange(key: K?, start: Long, stop: Long): List? = ops.lrange(key, start, stop).await() + + /** + * Get a range of elements from a list. + * + * @param channel the channel. + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun lrange(channel: ValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.lrange(channel, key, start, stop).await() + + /** + * Remove elements from a list. + * + * @param key the key. + * @param count the count type: long. + * @param value the value. + * @return Long integer-reply the number of removed elements. + * + **/ + override suspend fun lrem(key: K?, count: Long, value: V?): Long? = ops.lrem(key, count, value).await() + + /** + * Set the value of an element in a list by its index. + * + * @param key the key. + * @param index the index type: long. + * @param value the value. + * @return String simple-string-reply. + * + **/ + override suspend fun lset(key: K?, index: Long, value: V?): String? = ops.lset(key, index, value).await() + + /** + * Trim a list to the specified range. + * + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return String simple-string-reply. + * + **/ + override suspend fun ltrim(key: K?, start: Long, stop: Long): String? = ops.ltrim(key, start, stop).await() + + /** + * Remove and get the last element in a list. + * + * @param key the key. + * @return V bulk-string-reply the value of the last element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun rpop(key: K?): V? = ops.rpop(key).await() + + /** + * Remove the last element in a list, append it to another list and return it. + * + * @param source the source key. + * @param destination the destination type: key. + * @return V bulk-string-reply the element being popped and pushed. + * + **/ + override suspend fun rpoplpush(source: K?, destination: K?): V? = ops.rpoplpush(source, destination).await() + + /** + * Append one or multiple values to a list. + * + * @param key the key. + * @param values the value. + * @return Long integer-reply the length of the list after the push operation. + * + **/ + override suspend fun rpush(key: K?, vararg values: V?): Long? = ops.rpush(key, *values).await() + + /** + * Append values to a list, only if the list exists. + * + * @param key the key. + * @param values the values. + * @return Long integer-reply the length of the list after the push operation. + * + **/ + override suspend fun rpushx(key: K?, vararg values: V?): Long? = ops.rpushx(key, *values).await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisScriptingSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisScriptingSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..5dab2d8e3f --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisScriptingSuspendableAsyncCommands.kt @@ -0,0 +1,189 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.ScriptOutputType + + +/** + * Coroutine executed commands (based on async commands) for Scripting. {@link java.lang.String Lua scripts} are encoded by using the configured + * {@link io.lettuce.core.ClientOptions#getScriptCharset() charset}. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisScriptingSuspendableAsyncCommands(private val ops: RedisScriptingAsyncCommands) : RedisScriptingSuspendableCommands { + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type output type. + * @param keys key names. + * @param expected return type. + * @return script result. + * + **/ + override suspend fun eval(script: String?, type: ScriptOutputType?, vararg keys: K?): T? = ops.eval(script, type, *keys).await() + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type output type. + * @param keys key names. + * @param expected return type. + * @return script result. + * @since 6.0 + * + **/ + override suspend fun eval(script: ByteArray?, type: ScriptOutputType?, vararg keys: K?): T? = ops.eval(script, type, *keys).await() + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type the type. + * @param keys the keys. + * @param values the values. + * @param expected return type. + * @return script result. + * + **/ + override suspend fun eval(script: String?, type: ScriptOutputType?, keys: Array?, vararg values: V?): T? = ops.eval(script, type, keys, *values).await() + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type the type. + * @param keys the keys. + * @param values the values. + * @param expected return type. + * @return script result. + * @since 6.0 + * + **/ + override suspend fun eval(script: ByteArray?, type: ScriptOutputType?, keys: Array?, vararg values: V?): T? = ops.eval(script, type, keys, *values).await() + + /** + * Evaluates a script cached on the server side by its SHA1 digest. + * + * @param digest SHA1 of the script. + * @param type the type. + * @param keys the keys. + * @param expected return type. + * @return script result. + * + **/ + override suspend fun evalsha(digest: String?, type: ScriptOutputType?, vararg keys: K?): T? = ops.evalsha(digest, type, *keys).await() + + /** + * Execute a Lua script server side. + * + * @param digest SHA1 of the script. + * @param type the type. + * @param keys the keys. + * @param values the values. + * @param expected return type. + * @return script result. + * + **/ + override suspend fun evalsha(digest: String?, type: ScriptOutputType?, keys: Array?, vararg values: V?): T? = ops.evalsha(digest, type, keys, *values).await() + + /** + * Check existence of scripts in the script cache. + * + * @param digests script digests. + * @return List array-reply The command returns an array of integers that correspond to the specified SHA1 + * digest arguments. For every corresponding SHA1 digest of a script that actually exists in the script cache, an 1 + * is returned, otherwise 0 is returned. + * + **/ + override suspend fun scriptExists(vararg digests: String?): List? = ops.scriptExists(*digests).await() + + /** + * Remove all the scripts from the script cache. + * + * @return String simple-string-reply. + * + **/ + override suspend fun scriptFlush(): String? = ops.scriptFlush().await() + + /** + * Kill the script currently in execution. + * + * @return String simple-string-reply. + * + **/ + override suspend fun scriptKill(): String? = ops.scriptKill().await() + + /** + * Load the specified Lua script into the script cache. + * + * @param script script content. + * @return String bulk-string-reply This command returns the SHA1 digest of the script added into the script cache. + * @since 6.0 + * + **/ + override suspend fun scriptLoad(script: String?): String? = ops.scriptLoad(script).await() + + /** + * Load the specified Lua script into the script cache. + * + * @param script script content. + * @return String bulk-string-reply This command returns the SHA1 digest of the script added into the script cache. + * @since 6.0 + * + **/ + override suspend fun scriptLoad(script: ByteArray?): String? = ops.scriptLoad(script).await() + + /** + * Create a SHA1 digest from a Lua script. + * + * @param script script content. + * @return the SHA1 value. + * @since 6.0 + * + **/ + override suspend fun digest(script: String?): String? = ops.digest(script) + + /** + * Create a SHA1 digest from a Lua script. + * + * @param script script content. + * @return the SHA1 value. + * @since 6.0 + * + **/ + override suspend fun digest(script: ByteArray?): String? = ops.digest(script) + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisServerSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisServerSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..b5ab7d434a --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisServerSuspendableAsyncCommands.kt @@ -0,0 +1,460 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import java.util.Date +import io.lettuce.core.KillArgs +import io.lettuce.core.TrackingArgs +import io.lettuce.core.UnblockType +import io.lettuce.core.protocol.CommandType + + +/** + * Coroutine executed commands (based on async commands) for Server Control. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisServerSuspendableAsyncCommands(private val ops: RedisServerAsyncCommands) : RedisServerSuspendableCommands { + + /** + * Asynchronously rewrite the append-only file. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun bgrewriteaof(): String? = ops.bgrewriteaof().await() + + /** + * Asynchronously save the dataset to disk. + * + * @return String simple-string-reply. + * + **/ + override suspend fun bgsave(): String? = ops.bgsave().await() + + /** + * Control tracking of keys in the context of server-assisted client cache invalidation. + * + * @param enabled @code true} to enable key tracking. + * @return String simple-string-reply {@code OK}. + * @since 6.0 + * + **/ + override suspend fun clientCaching(enabled: Boolean): String? = ops.clientCaching(enabled).await() + + /** + * Get the current connection name. + * + * @return K bulk-string-reply The connection name, or a null bulk reply if no name is set. + * + **/ + override suspend fun clientGetname(): K? = ops.clientGetname().await() + + /** + * Returns the client ID we are redirecting our tracking notifications to. + * + * @return the ID of the client we are redirecting the notifications to. The command returns -1 if client tracking is not + * enabled, or 0 if client tracking is enabled but we are not redirecting the notifications to any client. + * @since 6.0 + * + **/ + override suspend fun clientGetredir(): Long? = ops.clientGetredir().await() + + /** + * Get the id of the current connection. + * + * @return Long The command just returns the ID of the current connection. + * @since 5.3 + * + **/ + override suspend fun clientId(): Long? = ops.clientId().await() + + /** + * Kill the connection of a client identified by ip:port. + * + * @param addr ip:port. + * @return String simple-string-reply {@code OK} if the connection exists and has been closed. + * + **/ + override suspend fun clientKill(addr: String?): String? = ops.clientKill(addr).await() + + /** + * Kill connections of clients which are filtered by {@code killArgs}. + * + * @param killArgs args for the kill operation. + * @return Long integer-reply number of killed connections. + * + **/ + override suspend fun clientKill(killArgs: KillArgs?): Long? = ops.clientKill(killArgs).await() + + /** + * Get the list of client connections. + * + * @return String bulk-string-reply a unique string, formatted as follows: One client connection per line (separated by LF), + * each line is composed of a succession of property=value fields separated by a space character. + * + **/ + override suspend fun clientList(): String? = ops.clientList().await() + + /** + * Stop processing commands from clients for some time. + * + * @param timeout the timeout value in milliseconds. + * @return String simple-string-reply The command returns OK or an error if the timeout is invalid. + * + **/ + override suspend fun clientPause(timeout: Long): String? = ops.clientPause(timeout).await() + + /** + * Set the current connection name. + * + * @param name the client name. + * @return simple-string-reply {@code OK} if the connection name was successfully set. + * + **/ + override suspend fun clientSetname(name: K?): String? = ops.clientSetname(name).await() + + /** + * Enables the tracking feature of the Redis server, that is used for server assisted client side caching. Tracking messages + * are either available when using the RESP3 protocol or through Pub/Sub notification when using RESP2. + * + * @param args for the CLIENT TRACKING operation. + * @return String simple-string-reply {@code OK}. + * @since 6.0 + * + **/ + override suspend fun clientTracking(args: TrackingArgs?): String? = ops.clientTracking(args).await() + + /** + * Unblock the specified blocked client. + * + * @param id the client id. + * @param type unblock type. + * @return Long integer-reply number of unblocked connections. + * @since 5.1 + * + **/ + override suspend fun clientUnblock(id: Long, type: UnblockType?): Long? = ops.clientUnblock(id, type).await() + + /** + * Returns an array reply of details about all Redis commands. + * + * @return List array-reply. + * + **/ + override suspend fun command(): List? = ops.command().await() + + /** + * Get total number of Redis commands. + * + * @return Long integer-reply of number of total commands in this Redis server. + * + **/ + override suspend fun commandCount(): Long? = ops.commandCount().await() + + /** + * Returns an array reply of details about the requested commands. + * + * @param commands the commands to query for. + * @return List array-reply. + * + **/ + override suspend fun commandInfo(vararg commands: String?): List? = ops.commandInfo(*commands).await() + + /** + * Returns an array reply of details about the requested commands. + * + * @param commands the commands to query for. + * @return List array-reply. + * + **/ + override suspend fun commandInfo(vararg commands: CommandType?): List? = ops.commandInfo(*commands).await() + + /** + * Get the value of a configuration parameter. + * + * @param parameter name of the parameter. + * @return Map bulk-string-reply. + * + **/ + override suspend fun configGet(parameter: String?): Map? = ops.configGet(parameter).await() + + /** + * Reset the stats returned by INFO. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun configResetstat(): String? = ops.configResetstat().await() + + /** + * Rewrite the configuration file with the in memory configuration. + * + * @return String simple-string-reply {@code OK} when the configuration was rewritten properly. Otherwise an error is + * returned. + * + **/ + override suspend fun configRewrite(): String? = ops.configRewrite().await() + + /** + * Set a configuration parameter to the given value. + * + * @param parameter the parameter name. + * @param value the parameter value. + * @return String simple-string-reply: {@code OK} when the configuration was set properly. Otherwise an error is returned. + * + **/ + override suspend fun configSet(parameter: String?, value: String?): String? = ops.configSet(parameter, value).await() + + /** + * Return the number of keys in the selected database. + * + * @return Long integer-reply. + * + **/ + override suspend fun dbsize(): Long? = ops.dbsize().await() + + /** + * Crash and recover. + * + * @param delay optional delay in milliseconds. + * @return String simple-string-reply. + * + **/ + override suspend fun debugCrashAndRecover(delay: Long?): String? = ops.debugCrashAndRecover(delay).await() + + /** + * Get debugging information about the internal hash-table state. + * + * @param db the database number. + * @return String simple-string-reply. + * + **/ + override suspend fun debugHtstats(db: Int): String? = ops.debugHtstats(db).await() + + /** + * Get debugging information about a key. + * + * @param key the key. + * @return String simple-string-reply. + * + **/ + override suspend fun debugObject(key: K?): String? = ops.debugObject(key).await() + + /** + * Make the server crash: Out of memory. + * + * @return nothing, because the server crashes before returning. + * + **/ + override suspend fun debugOom(): Unit? = ops.debugOom() + + /** + * Save RDB, clear the database and reload RDB. + * + * @return String simple-string-reply The commands returns OK on success. + * + **/ + override suspend fun debugReload(): String? = ops.debugReload().await() + + /** + * Restart the server gracefully. + * + * @param delay optional delay in milliseconds. + * @return String simple-string-reply. + * + **/ + override suspend fun debugRestart(delay: Long?): String? = ops.debugRestart(delay).await() + + /** + * Get debugging information about the internal SDS length. + * + * @param key the key. + * @return String simple-string-reply. + * + **/ + override suspend fun debugSdslen(key: K?): String? = ops.debugSdslen(key).await() + + /** + * Make the server crash: Invalid pointer access. + * + * @return nothing, because the server crashes before returning. + * + **/ + override suspend fun debugSegfault(): Unit? = ops.debugSegfault() + + /** + * Remove all keys from all databases. + * + * @return String simple-string-reply. + * + **/ + override suspend fun flushall(): String? = ops.flushall().await() + + /** + * Remove all keys asynchronously from all databases. + * + * @return String simple-string-reply. + * + **/ + override suspend fun flushallAsync(): String? = ops.flushallAsync().await() + + /** + * Remove all keys from the current database. + * + * @return String simple-string-reply. + * + **/ + override suspend fun flushdb(): String? = ops.flushdb().await() + + /** + * Remove all keys asynchronously from the current database. + * + * @return String simple-string-reply. + * + **/ + override suspend fun flushdbAsync(): String? = ops.flushdbAsync().await() + + /** + * Get information and statistics about the server. + * + * @return String bulk-string-reply as a collection of text lines. + * + **/ + override suspend fun info(): String? = ops.info().await() + + /** + * Get information and statistics about the server. + * + * @param section the section type: string. + * @return String bulk-string-reply as a collection of text lines. + * + **/ + override suspend fun info(section: String?): String? = ops.info(section).await() + + /** + * Get the UNIX time stamp of the last successful save to disk. + * + * @return Date integer-reply an UNIX time stamp. + * + **/ + override suspend fun lastsave(): Date? = ops.lastsave().await() + + /** + * Reports the number of bytes that a key and its value require to be stored in RAM. + * + * @return memory usage in bytes. + * @since 5.2 + * + **/ + override suspend fun memoryUsage(key: K?): Long? = ops.memoryUsage(key).await() + + /** + * Synchronously save the dataset to disk. + * + * @return String simple-string-reply The commands returns OK on success. + * + **/ + override suspend fun save(): String? = ops.save().await() + + /** + * Synchronously save the dataset to disk and then shut down the server. + * + * @param save @code true} force save operation. + * + **/ + override suspend fun shutdown(save: Boolean): Unit? = ops.shutdown(save) + + /** + * Make the server a replica of another instance, or promote it as master. + * + * @param host the host type: string. + * @param port the port type: string. + * @return String simple-string-reply. + * + **/ + override suspend fun slaveof(host: String?, port: Int): String? = ops.slaveof(host, port).await() + + /** + * Promote server as master. + * + * @return String simple-string-reply. + * + **/ + override suspend fun slaveofNoOne(): String? = ops.slaveofNoOne().await() + + /** + * Read the slow log. + * + * @return List deeply nested multi bulk replies. + * + **/ + override suspend fun slowlogGet(): List? = ops.slowlogGet().await() + + /** + * Read the slow log. + * + * @param count the count. + * @return List deeply nested multi bulk replies. + * + **/ + override suspend fun slowlogGet(count: Int): List? = ops.slowlogGet(count).await() + + /** + * Obtaining the current length of the slow log. + * + * @return Long length of the slow log. + * + **/ + override suspend fun slowlogLen(): Long? = ops.slowlogLen().await() + + /** + * Resetting the slow log. + * + * @return String simple-string-reply The commands returns OK on success. + * + **/ + override suspend fun slowlogReset(): String? = ops.slowlogReset().await() + + /** + * Return the current server time. + * + * @return List array-reply specifically: + * + * A multi bulk reply containing two elements: + * + * unix time in seconds. microseconds. + * + **/ + override suspend fun time(): List? = ops.time().await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisSetSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisSetSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..7e9bf5fdd1 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisSetSuspendableAsyncCommands.kt @@ -0,0 +1,347 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.ScanArgs +import io.lettuce.core.ScanCursor +import io.lettuce.core.StreamScanCursor +import io.lettuce.core.ValueScanCursor +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on async commands) for Sets. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisSetSuspendableAsyncCommands(private val ops: RedisSetAsyncCommands) : RedisSetSuspendableCommands { + + /** + * Add one or more members to a set. + * + * @param key the key. + * @param members the member type: value. + * @return Long integer-reply the number of elements that were added to the set, not including all the elements already + * present into the set. + * + **/ + override suspend fun sadd(key: K?, vararg members: V?): Long? = ops.sadd(key, *members).await() + + /** + * Get the number of members in a set. + * + * @param key the key. + * @return Long integer-reply the cardinality (number of elements) of the set, or {@code false} if {@code key} does not + * exist. + * + **/ + override suspend fun scard(key: K?): Long? = ops.scard(key).await() + + /** + * Subtract multiple sets. + * + * @param keys the key. + * @return Set array-reply list with members of the resulting set. + * + **/ + override suspend fun sdiff(vararg keys: K?): Set? = ops.sdiff(*keys).await() + + /** + * Subtract multiple sets. + * + * @param channel the channel. + * @param keys the keys. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun sdiff(channel: ValueStreamingChannel?, vararg keys: K?): Long? = ops.sdiff(channel, *keys).await() + + /** + * Subtract multiple sets and store the resulting set in a key. + * + * @param destination the destination type: key. + * @param keys the key. + * @return Long integer-reply the number of elements in the resulting set. + * + **/ + override suspend fun sdiffstore(destination: K?, vararg keys: K?): Long? = ops.sdiffstore(destination, *keys).await() + + /** + * Intersect multiple sets. + * + * @param keys the key. + * @return Set array-reply list with members of the resulting set. + * + **/ + override suspend fun sinter(vararg keys: K?): Set? = ops.sinter(*keys).await() + + /** + * Intersect multiple sets. + * + * @param channel the channel. + * @param keys the keys. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun sinter(channel: ValueStreamingChannel?, vararg keys: K?): Long? = ops.sinter(channel, *keys).await() + + /** + * Intersect multiple sets and store the resulting set in a key. + * + * @param destination the destination type: key. + * @param keys the key. + * @return Long integer-reply the number of elements in the resulting set. + * + **/ + override suspend fun sinterstore(destination: K?, vararg keys: K?): Long? = ops.sinterstore(destination, *keys).await() + + /** + * Determine if a given value is a member of a set. + * + * @param key the key. + * @param member the member type: value. + * @return Boolean integer-reply specifically: + * + * {@code true} if the element is a member of the set. {@code false} if the element is not a member of the set, or + * if {@code key} does not exist. + * + **/ + override suspend fun sismember(key: K?, member: V?): Boolean? = ops.sismember(key, member).await() + + /** + * Move a member from one set to another. + * + * @param source the source key. + * @param destination the destination type: key. + * @param member the member type: value. + * @return Boolean integer-reply specifically: + * + * {@code true} if the element is moved. {@code false} if the element is not a member of {@code source} and no + * operation was performed. + * + **/ + override suspend fun smove(source: K?, destination: K?, member: V?): Boolean? = ops.smove(source, destination, member).await() + + /** + * Get all the members in a set. + * + * @param key the key. + * @return Set array-reply all elements of the set. + * + **/ + override suspend fun smembers(key: K?): Set? = ops.smembers(key).await() + + /** + * Get all the members in a set. + * + * @param channel the channel. + * @param key the keys. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun smembers(channel: ValueStreamingChannel?, key: K?): Long? = ops.smembers(channel, key).await() + + /** + * Remove and return a random member from a set. + * + * @param key the key. + * @return V bulk-string-reply the removed element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun spop(key: K?): V? = ops.spop(key).await() + + /** + * Remove and return one or multiple random members from a set. + * + * @param key the key. + * @param count number of members to pop. + * @return V bulk-string-reply the removed element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun spop(key: K?, count: Long): Set? = ops.spop(key, count).await() + + /** + * Get one random member from a set. + * + * @param key the key. + * @return V bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply with the + * randomly selected element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun srandmember(key: K?): V? = ops.srandmember(key).await() + + /** + * Get one or multiple random members from a set. + * + * @param key the key. + * @param count the count type: long. + * @return Set bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply + * with the randomly selected element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun srandmember(key: K?, count: Long): List? = ops.srandmember(key, count).await() + + /** + * Get one or multiple random members from a set. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param count the count. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun srandmember(channel: ValueStreamingChannel?, key: K?, count: Long): Long? = ops.srandmember(channel, key, count).await() + + /** + * Remove one or more members from a set. + * + * @param key the key. + * @param members the member type: value. + * @return Long integer-reply the number of members that were removed from the set, not including non existing members. + * + **/ + override suspend fun srem(key: K?, vararg members: V?): Long? = ops.srem(key, *members).await() + + /** + * Add multiple sets. + * + * @param keys the key. + * @return Set array-reply list with members of the resulting set. + * + **/ + override suspend fun sunion(vararg keys: K?): Set? = ops.sunion(*keys).await() + + /** + * Add multiple sets. + * + * @param channel streaming channel that receives a call for every value. + * @param keys the keys. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun sunion(channel: ValueStreamingChannel?, vararg keys: K?): Long? = ops.sunion(channel, *keys).await() + + /** + * Add multiple sets and store the resulting set in a key. + * + * @param destination the destination type: key. + * @param keys the key. + * @return Long integer-reply the number of elements in the resulting set. + * + **/ + override suspend fun sunionstore(destination: K?, vararg keys: K?): Long? = ops.sunionstore(destination, *keys).await() + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @return ValueScanCursor scan cursor. + * + **/ + override suspend fun sscan(key: K?): ValueScanCursor? = ops.sscan(key).await() + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @param scanArgs scan arguments. + * @return ValueScanCursor scan cursor. + * + **/ + override suspend fun sscan(key: K?, scanArgs: ScanArgs?): ValueScanCursor? = ops.sscan(key, scanArgs).await() + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return ValueScanCursor scan cursor. + * + **/ + override suspend fun sscan(key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): ValueScanCursor? = ops.sscan(key, scanCursor, scanArgs).await() + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return ValueScanCursor scan cursor. + * + **/ + override suspend fun sscan(key: K?, scanCursor: ScanCursor?): ValueScanCursor? = ops.sscan(key, scanCursor).await() + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun sscan(channel: ValueStreamingChannel?, key: K?): StreamScanCursor? = ops.sscan(channel, key).await() + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun sscan(channel: ValueStreamingChannel?, key: K?, scanArgs: ScanArgs?): StreamScanCursor? = ops.sscan(channel, key, scanArgs).await() + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun sscan(channel: ValueStreamingChannel?, key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? = ops.sscan(channel, key, scanCursor, scanArgs).await() + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun sscan(channel: ValueStreamingChannel?, key: K?, scanCursor: ScanCursor?): StreamScanCursor? = ops.sscan(channel, key, scanCursor).await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisSortedSetSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisSortedSetSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..dca3360389 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisSortedSetSuspendableAsyncCommands.kt @@ -0,0 +1,1368 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.* +import io.lettuce.core.output.ScoredValueStreamingChannel +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on async commands) for Sorted Sets. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisSortedSetSuspendableAsyncCommands(private val ops: RedisSortedSetAsyncCommands) : RedisSortedSetSuspendableCommands { + + /** + * Removes and returns a member with the lowest scores in the sorted set stored at one of the keys. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue> multi-bulk containing the name of the key, the score and the popped + * member. + * @since 5.1 + * + **/ + override suspend fun bzpopmin(timeout: Long, vararg keys: K?): KeyValue>? = ops.bzpopmin(timeout, *keys).await() + + /** + * Removes and returns a member with the highest scores in the sorted set stored at one of the keys. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue> multi-bulk containing the name of the key, the score and the popped + * member. + * @since 5.1 + * + **/ + override suspend fun bzpopmax(timeout: Long, vararg keys: K?): KeyValue>? = ops.bzpopmax(timeout, *keys).await() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, score: Double, member: V?): Long? = ops.zadd(key, score, member).await() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param scoresAndValues the scoresAndValue tuples (score,value,score,value,...). + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, vararg scoresAndValues: Any?): Long? = ops.zadd(key, *scoresAndValues).await() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param scoredValues the scored values. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, vararg scoredValues: ScoredValue?): Long? = ops.zadd(key, *scoredValues).await() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param zAddArgs arguments for zadd. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, zAddArgs: ZAddArgs?, score: Double, member: V?): Long? = ops.zadd(key, zAddArgs, score, member).await() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param zAddArgs arguments for zadd. + * @param scoresAndValues the scoresAndValue tuples (score,value,score,value,...). + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, zAddArgs: ZAddArgs?, vararg scoresAndValues: Any?): Long? = ops.zadd(key, zAddArgs, *scoresAndValues).await() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the ke. + * @param zAddArgs arguments for zadd. + * @param scoredValues the scored values. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, zAddArgs: ZAddArgs?, vararg scoredValues: ScoredValue?): Long? = ops.zadd(key, zAddArgs, *scoredValues).await() + + /** + * Add one or more members to a sorted set, or update its score if it already exists applying the {@code INCR} option. ZADD + * acts like ZINCRBY. + * + * @param key the key. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: The total number of elements changed. + * + **/ + override suspend fun zaddincr(key: K?, score: Double, member: V?): Double? = ops.zaddincr(key, score, member).await() + + /** + * Add one or more members to a sorted set, or update its score if it already exists applying the {@code INCR} option. ZADD + * acts like ZINCRBY. + * + * @param key the key. + * @param zAddArgs arguments for zadd. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: The total number of elements changed. + * @since 4.3 + * + **/ + override suspend fun zaddincr(key: K?, zAddArgs: ZAddArgs?, score: Double, member: V?): Double? = ops.zaddincr(key, zAddArgs, score, member).await() + + /** + * Get the number of members in a sorted set. + * + * @param key the key. + * @return Long integer-reply the cardinality (number of elements) of the sorted set, or {@code false} if {@code key} does + * not exist. + * + **/ + override suspend fun zcard(key: K?): Long? = ops.zcard(key).await() + + /** + * Count the members in a sorted set with scores within the given values. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements in the specified score range. + * @deprecated Use {@link #zcount(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zcount(key: K?, min: Double, max: Double): Long? = ops.zcount(key, min, max).await() + + /** + * Count the members in a sorted set with scores within the given values. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements in the specified score range. + * @deprecated Use {@link #zcount(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zcount(key: K?, min: String?, max: String?): Long? = ops.zcount(key, min, max).await() + + /** + * Count the members in a sorted set with scores within the given {@link Range}. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zcount(key: K?, range: Range?): Long? = ops.zcount(key, range).await() + + /** + * Increment the score of a member in a sorted set. + * + * @param key the key. + * @param amount the increment type: long. + * @param member the member type: value. + * @return Double bulk-string-reply the new score of {@code member} (a double precision floating point number), represented + * as string. + * + **/ + override suspend fun zincrby(key: K?, amount: Double, member: V?): Double? = ops.zincrby(key, amount, member).await() + + /** + * Intersect multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination the destination. + * @param keys the keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + override suspend fun zinterstore(destination: K?, vararg keys: K?): Long? = ops.zinterstore(destination, *keys).await() + + /** + * Intersect multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination the destination. + * @param storeArgs the storeArgs. + * @param keys the keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + override suspend fun zinterstore(destination: K?, storeArgs: ZStoreArgs?, vararg keys: K?): Long? = ops.zinterstore(destination, storeArgs, *keys).await() + + /** + * Count the number of members in a sorted set between a given lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements in the specified score range. + * @deprecated Use {@link #zlexcount(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zlexcount(key: K?, min: String?, max: String?): Long? = ops.zlexcount(key, min, max).await() + + /** + * Count the number of members in a sorted set between a given lexicographical range. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zlexcount(key: K?, range: Range?): Long? = ops.zlexcount(key, range).await() + + /** + * Removes and returns up to count members with the lowest scores in the sorted set stored at key. + * + * @param key the key. + * @return ScoredValue the removed element. + * @since 5.1 + * + **/ + override suspend fun zpopmin(key: K?): ScoredValue? = ops.zpopmin(key).await() + + /** + * Removes and returns up to count members with the lowest scores in the sorted set stored at key. + * + * @param key the key. + * @param count the number of elements to return. + * @return List> array-reply list of popped scores and elements. + * @since 5.1 + * + **/ + override suspend fun zpopmin(key: K?, count: Long): List>? = ops.zpopmin(key, count).await() + + /** + * Removes and returns up to count members with the highest scores in the sorted set stored at key. + * + * @param key the key. + * @return ScoredValue the removed element. + * @since 5.1 + * + **/ + override suspend fun zpopmax(key: K?): ScoredValue? = ops.zpopmax(key).await() + + /** + * Removes and returns up to count members with the highest scores in the sorted set stored at key. + * + * @param key the key. + * @param count the number of elements to return. + * @return List> array-reply list of popped scores and elements. + * @since 5.1 + * + **/ + override suspend fun zpopmax(key: K?, count: Long): List>? = ops.zpopmax(key, count).await() + + /** + * Return a range of members in a sorted set, by index. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun zrange(key: K?, start: Long, stop: Long): List? = ops.zrange(key, start, stop).await() + + /** + * Return a range of members in a sorted set, by index. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrange(channel: ValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.zrange(channel, key, start, stop).await() + + /** + * Return a range of members with scores in a sorted set, by index. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun zrangeWithScores(key: K?, start: Long, stop: Long): List>? = ops.zrangeWithScores(key, start, stop).await() + + /** + * Stream over a range of members with scores in a sorted set, by index. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrangeWithScores(channel: ScoredValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.zrangeWithScores(channel, key, start, stop).await() + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified range. + * @deprecated Use {@link #zrangebylex(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebylex(key: K?, min: String?, max: String?): List? = ops.zrangebylex(key, min, max).await() + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrangebylex(key: K?, range: Range?): List? = ops.zrangebylex(key, range).await() + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified range. + * @deprecated Use {@link #zrangebylex(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebylex(key: K?, min: String?, max: String?, offset: Long, count: Long): List? = ops.zrangebylex(key, min, max, offset, count).await() + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrangebylex(key: K?, range: Range?, limit: Limit?): List? = ops.zrangebylex(key, range, limit).await() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(key: K?, min: Double, max: Double): List? = ops.zrangebyscore(key, min, max).await() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(key: K?, min: String?, max: String?): List? = ops.zrangebyscore(key, min, max).await() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscore(key: K?, range: Range?): List? = ops.zrangebyscore(key, range).await() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(key: K?, min: Double, max: Double, offset: Long, count: Long): List? = ops.zrangebyscore(key, min, max, offset, count).await() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(key: K?, min: String?, max: String?, offset: Long, count: Long): List? = ops.zrangebyscore(key, min, max, offset, count).await() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscore(key: K?, range: Range?, limit: Limit?): List? = ops.zrangebyscore(key, range, limit).await() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: Double, max: Double): Long? = ops.zrangebyscore(channel, key, min, max).await() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: String?, max: String?): Long? = ops.zrangebyscore(channel, key, min, max).await() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?): Long? = ops.zrangebyscore(channel, key, range).await() + + /** + * Stream over range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: Double, max: Double, offset: Long, count: Long): Long? = ops.zrangebyscore(channel, key, min, max, offset, count).await() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: String?, max: String?, offset: Long, count: Long): Long? = ops.zrangebyscore(channel, key, min, max, offset, count).await() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? = ops.zrangebyscore(channel, key, range, limit).await() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(key: K?, min: Double, max: Double): List>? = ops.zrangebyscoreWithScores(key, min, max).await() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(key: K?, min: String?, max: String?): List>? = ops.zrangebyscoreWithScores(key, min, max).await() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @return List> array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscoreWithScores(key: K?, range: Range?): List>? = ops.zrangebyscoreWithScores(key, range).await() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(key: K?, min: Double, max: Double, offset: Long, count: Long): List>? = ops.zrangebyscoreWithScores(key, min, max, offset, count).await() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(key: K?, min: String?, max: String?, offset: Long, count: Long): List>? = ops.zrangebyscoreWithScores(key, min, max, offset, count).await() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List> array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscoreWithScores(key: K?, range: Range?, limit: Limit?): List>? = ops.zrangebyscoreWithScores(key, range, limit).await() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: Double, max: Double): Long? = ops.zrangebyscoreWithScores(channel, key, min, max).await() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: String?, max: String?): Long? = ops.zrangebyscoreWithScores(channel, key, min, max).await() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?): Long? = ops.zrangebyscoreWithScores(channel, key, range).await() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: Double, max: Double, offset: Long, count: Long): Long? = ops.zrangebyscoreWithScores(channel, key, min, max, offset, count).await() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: String?, max: String?, offset: Long, count: Long): Long? = ops.zrangebyscoreWithScores(channel, key, min, max, offset, count).await() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? = ops.zrangebyscoreWithScores(channel, key, range, limit).await() + + /** + * Determine the index of a member in a sorted set. + * + * @param key the key. + * @param member the member type: value. + * @return Long integer-reply the rank of {@code member}. If {@code member} does not exist in the sorted set or {@code key} + * does not exist,. + * + **/ + override suspend fun zrank(key: K?, member: V?): Long? = ops.zrank(key, member).await() + + /** + * Remove one or more members from a sorted set. + * + * @param key the key. + * @param members the member type: value. + * @return Long integer-reply specifically: + * + * The number of members removed from the sorted set, not including non existing members. + * + **/ + override suspend fun zrem(key: K?, vararg members: V?): Long? = ops.zrem(key, *members).await() + + /** + * Remove all members in a sorted set between the given lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements removed. + * @deprecated Use {@link #zremrangebylex(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zremrangebylex(key: K?, min: String?, max: String?): Long? = ops.zremrangebylex(key, min, max).await() + + /** + * Remove all members in a sorted set between the given lexicographical range. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements removed. + * @since 4.3 + * + **/ + override suspend fun zremrangebylex(key: K?, range: Range?): Long? = ops.zremrangebylex(key, range).await() + + /** + * Remove all members in a sorted set within the given indexes. + * + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return Long integer-reply the number of elements removed. + * + **/ + override suspend fun zremrangebyrank(key: K?, start: Long, stop: Long): Long? = ops.zremrangebyrank(key, start, stop).await() + + /** + * Remove all members in a sorted set within the given scores. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements removed. + * @deprecated Use {@link #zremrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zremrangebyscore(key: K?, min: Double, max: Double): Long? = ops.zremrangebyscore(key, min, max).await() + + /** + * Remove all members in a sorted set within the given scores. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements removed. + * @deprecated Use {@link #zremrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zremrangebyscore(key: K?, min: String?, max: String?): Long? = ops.zremrangebyscore(key, min, max).await() + + /** + * Remove all members in a sorted set within the given scores. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements removed. + * @since 4.3 + * + **/ + override suspend fun zremrangebyscore(key: K?, range: Range?): Long? = ops.zremrangebyscore(key, range).await() + + /** + * Return a range of members in a sorted set, by index, with scores ordered from high to low. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun zrevrange(key: K?, start: Long, stop: Long): List? = ops.zrevrange(key, start, stop).await() + + /** + * Stream over a range of members in a sorted set, by index, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrevrange(channel: ValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.zrevrange(channel, key, start, stop).await() + + /** + * Return a range of members with scores in a sorted set, by index, with scores ordered from high to low. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun zrevrangeWithScores(key: K?, start: Long, stop: Long): List>? = ops.zrevrangeWithScores(key, start, stop).await() + + /** + * Stream over a range of members with scores in a sorted set, by index, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrevrangeWithScores(channel: ScoredValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.zrevrangeWithScores(channel, key, start, stop).await() + + /** + * Return a range of members in a sorted set, by lexicographical range ordered from high to low. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebylex(key: K?, range: Range?): List? = ops.zrevrangebylex(key, range).await() + + /** + * Return a range of members in a sorted set, by lexicographical range ordered from high to low. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebylex(key: K?, range: Range?, limit: Limit?): List? = ops.zrevrangebylex(key, range, limit).await() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(key: K?, max: Double, min: Double): List? = ops.zrevrangebyscore(key, max, min).await() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(key: K?, max: String?, min: String?): List? = ops.zrevrangebyscore(key, max, min).await() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscore(key: K?, range: Range?): List? = ops.zrevrangebyscore(key, range).await() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the withscores. + * @param count the null. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(key: K?, max: Double, min: Double, offset: Long, count: Long): List? = ops.zrevrangebyscore(key, max, min, offset, count).await() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(key: K?, max: String?, min: String?, offset: Long, count: Long): List? = ops.zrevrangebyscore(key, max, min, offset, count).await() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscore(key: K?, range: Range?, limit: Limit?): List? = ops.zrevrangebyscore(key, range, limit).await() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param max max score. + * @param min min score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: Double, min: Double): Long? = ops.zrevrangebyscore(channel, key, max, min).await() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: String?, min: String?): Long? = ops.zrevrangebyscore(channel, key, max, min).await() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?): Long? = ops.zrevrangebyscore(channel, key, range).await() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: Double, min: Double, offset: Long, count: Long): Long? = ops.zrevrangebyscore(channel, key, max, min, offset, count).await() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: String?, min: String?, offset: Long, count: Long): Long? = ops.zrevrangebyscore(channel, key, max, min, offset, count).await() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? = ops.zrevrangebyscore(channel, key, range, limit).await() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(key: K?, max: Double, min: Double): List>? = ops.zrevrangebyscoreWithScores(key, max, min).await() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(key: K?, max: String?, min: String?): List>? = ops.zrevrangebyscoreWithScores(key, max, min).await() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @return List> array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscoreWithScores(key: K?, range: Range?): List>? = ops.zrevrangebyscoreWithScores(key, range).await() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the offset. + * @param count the count. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(key: K?, max: Double, min: Double, offset: Long, count: Long): List>? = ops.zrevrangebyscoreWithScores(key, max, min, offset, count).await() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(key: K?, max: String?, min: String?, offset: Long, count: Long): List>? = ops.zrevrangebyscoreWithScores(key, max, min, offset, count).await() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @param limit limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscoreWithScores(key: K?, range: Range?, limit: Limit?): List>? = ops.zrevrangebyscoreWithScores(key, range, limit).await() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: Double, min: Double): Long? = ops.zrevrangebyscoreWithScores(channel, key, max, min).await() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: String?, min: String?): Long? = ops.zrevrangebyscoreWithScores(channel, key, max, min).await() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?): Long? = ops.zrevrangebyscoreWithScores(channel, key, range).await() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: Double, min: Double, offset: Long, count: Long): Long? = ops.zrevrangebyscoreWithScores(channel, key, max, min, offset, count).await() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: String?, min: String?, offset: Long, count: Long): Long? = ops.zrevrangebyscoreWithScores(channel, key, max, min, offset, count).await() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? = ops.zrevrangebyscoreWithScores(channel, key, range, limit).await() + + /** + * Determine the index of a member in a sorted set, with scores ordered from high to low. + * + * @param key the key. + * @param member the member type: value. + * @return Long integer-reply the rank of {@code member}. If {@code member} does not exist in the sorted set or {@code key} + * does not exist,. + * + **/ + override suspend fun zrevrank(key: K?, member: V?): Long? = ops.zrevrank(key, member).await() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @return ScoredValueScanCursor scan cursor. + * + **/ + override suspend fun zscan(key: K?): ScoredValueScanCursor? = ops.zscan(key).await() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @param scanArgs scan arguments. + * @return ScoredValueScanCursor scan cursor. + * + **/ + override suspend fun zscan(key: K?, scanArgs: ScanArgs?): ScoredValueScanCursor? = ops.zscan(key, scanArgs).await() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return ScoredValueScanCursor scan cursor. + * + **/ + override suspend fun zscan(key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): ScoredValueScanCursor? = ops.zscan(key, scanCursor, scanArgs).await() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return ScoredValueScanCursor scan cursor. + * + **/ + override suspend fun zscan(key: K?, scanCursor: ScanCursor?): ScoredValueScanCursor? = ops.zscan(key, scanCursor).await() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?): StreamScanCursor? = ops.zscan(channel, key).await() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?, scanArgs: ScanArgs?): StreamScanCursor? = ops.zscan(channel, key, scanArgs).await() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? = ops.zscan(channel, key, scanCursor, scanArgs).await() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?, scanCursor: ScanCursor?): StreamScanCursor? = ops.zscan(channel, key, scanCursor).await() + + /** + * Get the score associated with the given member in a sorted set. + * + * @param key the key. + * @param member the member type: value. + * @return Double bulk-string-reply the score of {@code member} (a double precision floating point number), represented as + * string. + * + **/ + override suspend fun zscore(key: K?, member: V?): Double? = ops.zscore(key, member).await() + + /** + * Add multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination destination key. + * @param keys source keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + override suspend fun zunionstore(destination: K?, vararg keys: K?): Long? = ops.zunionstore(destination, *keys).await() + + /** + * Add multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination the destination. + * @param storeArgs the storeArgs. + * @param keys the keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + override suspend fun zunionstore(destination: K?, storeArgs: ZStoreArgs?, vararg keys: K?): Long? = ops.zunionstore(destination, storeArgs, *keys).await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisStreamSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisStreamSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..19194e6417 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisStreamSuspendableAsyncCommands.kt @@ -0,0 +1,374 @@ +/* + * Copyright 2018-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.Consumer +import io.lettuce.core.Limit +import io.lettuce.core.Range +import io.lettuce.core.StreamMessage +import io.lettuce.core.XAddArgs +import io.lettuce.core.XGroupCreateArgs +import io.lettuce.core.XReadArgs +import io.lettuce.core.XClaimArgs +import io.lettuce.core.XReadArgs.StreamOffset +import io.lettuce.core.models.stream.PendingMessage +import io.lettuce.core.models.stream.PendingMessages + + +/** + * Coroutine executed commands (based on async commands) for Streams. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 5.1 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisStreamSuspendableAsyncCommands(private val ops: RedisStreamAsyncCommands) : RedisStreamSuspendableCommands { + + /** + * Acknowledge one or more messages as processed. + * + * @param key the stream key. + * @param group name of the consumer group. + * @param messageIds message Id's to acknowledge. + * @return simple-reply the lenght of acknowledged messages. + * + **/ + override suspend fun xack(key: K?, group: K?, vararg messageIds: String?): Long? = ops.xack(key, group, *messageIds).await() + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param body message body. + * @return simple-reply the message Id. + * + **/ + override suspend fun xadd(key: K?, body: Map?): String? = ops.xadd(key, body).await() + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param args + * @param body message body. + * @return simple-reply the message Id. + * + **/ + override suspend fun xadd(key: K?, args: XAddArgs?, body: Map?): String? = ops.xadd(key, args, body).await() + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param keysAndValues message body. + * @return simple-reply the message Id. + * + **/ + override suspend fun xadd(key: K?, vararg keysAndValues: Any?): String? = ops.xadd(key, *keysAndValues).await() + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param args + * @param keysAndValues message body. + * @return simple-reply the message Id. + * + **/ + override suspend fun xadd(key: K?, args: XAddArgs?, vararg keysAndValues: Any?): String? = ops.xadd(key, args, *keysAndValues).await() + + /** + * Gets ownership of one or multiple messages in the Pending Entries List of a given stream consumer group. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @param minIdleTime + * @param messageIds message Id's to claim. + * @return simple-reply the {@link StreamMessage}. + * + **/ + override suspend fun xclaim(key: K?, consumer: Consumer?, minIdleTime: Long, vararg messageIds: String?): List>? = ops.xclaim(key, consumer, minIdleTime, *messageIds).await() + + /** + * Gets ownership of one or multiple messages in the Pending Entries List of a given stream consumer group. + *

+ * Note that setting the {@code JUSTID} flag (calling this method with {@link XClaimArgs#justid()}) suppresses the message + * bode and {@link StreamMessage#getBody()} is {@code null}. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @param args + * @param messageIds message Id's to claim. + * @return simple-reply the {@link StreamMessage}. + * + **/ + override suspend fun xclaim(key: K?, consumer: Consumer?, args: XClaimArgs?, vararg messageIds: String?): List>? = ops.xclaim(key, consumer, args, *messageIds).await() + + /** + * Removes the specified entries from the stream. Returns the number of items deleted, that may be different from the number + * of IDs passed in case certain IDs do not exist. + * + * @param key the stream key. + * @param messageIds stream message Id's. + * @return simple-reply number of removed entries. + * + **/ + override suspend fun xdel(key: K?, vararg messageIds: String?): Long? = ops.xdel(key, *messageIds).await() + + /** + * Create a consumer group. + * + * @param streamOffset name of the stream containing the offset to set. + * @param group name of the consumer group. + * @return simple-reply {@code true} if successful. + * + **/ + override suspend fun xgroupCreate(streamOffset: StreamOffset?, group: K?): String? = ops.xgroupCreate(streamOffset, group).await() + + /** + * Create a consumer group. + * + * @param streamOffset name of the stream containing the offset to set. + * @param group name of the consumer group. + * @param args + * @return simple-reply {@code true} if successful. + * @since 5.2 + * + **/ + override suspend fun xgroupCreate(streamOffset: StreamOffset?, group: K?, args: XGroupCreateArgs?): String? = ops.xgroupCreate(streamOffset, group, args).await() + + /** + * Delete a consumer from a consumer group. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @return Long integer-reply number of pending messages. + * + **/ + override suspend fun xgroupDelconsumer(key: K?, consumer: Consumer?): Long? = ops.xgroupDelconsumer(key, consumer).await() + + /** + * Destroy a consumer group. + * + * @param key the stream key. + * @param group name of the consumer group. + * @return simple-reply {@code true} if successful. + * + **/ + override suspend fun xgroupDestroy(key: K?, group: K?): Boolean? = ops.xgroupDestroy(key, group).await() + + /** + * Set the current {@code group} id. + * + * @param streamOffset name of the stream containing the offset to set. + * @param group name of the consumer group. + * @return simple-reply OK. + * + **/ + override suspend fun xgroupSetid(streamOffset: StreamOffset?, group: K?): String? = ops.xgroupSetid(streamOffset, group).await() + + /** + * Retrieve information about the stream at {@code key}. + * + * @param key the stream key. + * @return List array-reply. + * @since 5.2 + * + **/ + override suspend fun xinfoStream(key: K?): List? = ops.xinfoStream(key).await() + + /** + * Retrieve information about the stream consumer groups at {@code key}. + * + * @param key the stream key. + * @return List array-reply. + * @since 5.2 + * + **/ + override suspend fun xinfoGroups(key: K?): List? = ops.xinfoGroups(key).await() + + /** + * Retrieve information about consumer groups of group {@code group} and stream at {@code key}. + * + * @param key the stream key. + * @param group name of the consumer group. + * @return List array-reply. + * @since 5.2 + * + **/ + override suspend fun xinfoConsumers(key: K?, group: K?): List? = ops.xinfoConsumers(key, group).await() + + /** + * Get the length of a steam. + * + * @param key the stream key. + * @return simple-reply the lenght of the stream. + * + **/ + override suspend fun xlen(key: K?): Long? = ops.xlen(key).await() + + /** + * Read pending messages from a stream for a {@code group}. + * + * @param key the stream key. + * @param group name of the consumer group. + * @return List array-reply list pending entries. + * + **/ + override suspend fun xpending(key: K?, group: K?): PendingMessages? = ops.xpending(key, group).await() + + /** + * Read pending messages from a stream within a specific {@link Range}. + * + * @param key the stream key. + * @param group name of the consumer group. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xpending(key: K?, group: K?, range: Range?, limit: Limit?): List? = ops.xpending(key, group, range, limit).await() + + /** + * Read pending messages from a stream within a specific {@link Range}. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xpending(key: K?, consumer: Consumer?, range: Range?, limit: Limit?): List? = ops.xpending(key, consumer, range, limit).await() + + /** + * Read messages from a stream within a specific {@link Range}. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xrange(key: K?, range: Range?): List>? = ops.xrange(key, range).await() + + /** + * Read messages from a stream within a specific {@link Range} applying a {@link Limit}. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xrange(key: K?, range: Range?, limit: Limit?): List>? = ops.xrange(key, range, limit).await() + + /** + * Read messages from one or more {@link StreamOffset}s. + * + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xread(vararg streams: StreamOffset?): List>? = ops.xread(*streams).await() + + /** + * Read messages from one or more {@link StreamOffset}s. + * + * @param args read arguments. + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xread(args: XReadArgs?, vararg streams: StreamOffset?): List>? = ops.xread(args, *streams).await() + + /** + * Read messages from one or more {@link StreamOffset}s using a consumer group. + * + * @param consumer consumer/group. + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xreadgroup(consumer: Consumer?, vararg streams: StreamOffset?): List>? = ops.xreadgroup(consumer, *streams).await() + + /** + * Read messages from one or more {@link StreamOffset}s using a consumer group. + * + * @param consumer consumer/group. + * @param args read arguments. + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xreadgroup(consumer: Consumer?, args: XReadArgs?, vararg streams: StreamOffset?): List>? = ops.xreadgroup(consumer, args, *streams).await() + + /** + * Read messages from a stream within a specific {@link Range} in reverse order. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xrevrange(key: K?, range: Range?): List>? = ops.xrevrange(key, range).await() + + /** + * Read messages from a stream within a specific {@link Range} applying a {@link Limit} in reverse order. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xrevrange(key: K?, range: Range?, limit: Limit?): List>? = ops.xrevrange(key, range, limit).await() + + /** + * Trims the stream to {@code count} elements. + * + * @param key the stream key. + * @param count length of the stream. + * @return simple-reply number of removed entries. + * + **/ + override suspend fun xtrim(key: K?, count: Long): Long? = ops.xtrim(key, count).await() + + /** + * Trims the stream to {@code count} elements. + * + * @param key the stream key. + * @param approximateTrimming @code true} to trim approximately using the {@code ~} flag. + * @param count length of the stream. + * @return simple-reply number of removed entries. + * + **/ + override suspend fun xtrim(key: K?, approximateTrimming: Boolean, count: Long): Long? = ops.xtrim(key, approximateTrimming, count).await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisStringSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisStringSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..4b3be98975 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisStringSuspendableAsyncCommands.kt @@ -0,0 +1,434 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.BitFieldArgs +import io.lettuce.core.KeyValue +import io.lettuce.core.SetArgs +import io.lettuce.core.StrAlgoArgs +import io.lettuce.core.StringMatchResult +import io.lettuce.core.output.KeyValueStreamingChannel + + +/** + * Coroutine executed commands (based on async commands) for Strings. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisStringSuspendableAsyncCommands(private val ops: RedisStringAsyncCommands) : RedisStringSuspendableCommands { + + /** + * Append a value to a key. + * + * @param key the key. + * @param value the value. + * @return Long integer-reply the length of the string after the append operation. + * + **/ + override suspend fun append(key: K?, value: V?): Long? = ops.append(key, value).await() + + /** + * Count set bits in a string. + * + * @param key the key. + * @return Long integer-reply The number of bits set to 1. + * + **/ + override suspend fun bitcount(key: K?): Long? = ops.bitcount(key).await() + + /** + * Count set bits in a string. + * + * @param key the key. + * @param start the start. + * @param end the end. + * @return Long integer-reply The number of bits set to 1. + * + **/ + override suspend fun bitcount(key: K?, start: Long, end: Long): Long? = ops.bitcount(key, start, end).await() + + /** + * Execute {@code BITFIELD} with its subcommands. + * + * @param key the key. + * @param bitFieldArgs the args containing subcommands, must not be {@code null}. + * @return Long bulk-reply the results from the bitfield commands. + * + **/ + override suspend fun bitfield(key: K?, bitFieldArgs: BitFieldArgs?): List? = ops.bitfield(key, bitFieldArgs).await() + + /** + * Find first bit set or clear in a string. + * + * @param key the key. + * @param state the state. + * @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request. + * + * If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is + * returned. + * + * If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns + * the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the + * command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1. + * + * Basically the function consider the right of the string as padded with zeros if you look for clear bits and + * specify no range or the start argument only. + * + **/ + override suspend fun bitpos(key: K?, state: Boolean): Long? = ops.bitpos(key, state).await() + + /** + * Find first bit set or clear in a string. + * + * @param key the key. + * @param state the bit type: long. + * @param start the start type: long. + * @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request. + * + * If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is + * returned. + * + * If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns + * the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the + * command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1. + * + * Basically the function consider the right of the string as padded with zeros if you look for clear bits and + * specify no range or the start argument only. + * @since 5.0.1 + * + **/ + override suspend fun bitpos(key: K?, state: Boolean, start: Long): Long? = ops.bitpos(key, state, start).await() + + /** + * Find first bit set or clear in a string. + * + * @param key the key. + * @param state the bit type: long. + * @param start the start type: long. + * @param end the end type: long. + * @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request. + * + * If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is + * returned. + * + * If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns + * the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the + * command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1. + * + * Basically the function consider the right of the string as padded with zeros if you look for clear bits and + * specify no range or the start argument only. + * + * However this behavior changes if you are looking for clear bits and specify a range with both + * start and end. If no clear bit is found in the specified range, the function + * returns -1 as the user specified a clear range and there are no 0 bits in that range. + * + **/ + override suspend fun bitpos(key: K?, state: Boolean, start: Long, end: Long): Long? = ops.bitpos(key, state, start, end).await() + + /** + * Perform bitwise AND between strings. + * + * @param destination result key of the operation. + * @param keys operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + override suspend fun bitopAnd(destination: K?, vararg keys: K?): Long? = ops.bitopAnd(destination, *keys).await() + + /** + * Perform bitwise NOT between strings. + * + * @param destination result key of the operation. + * @param source operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + override suspend fun bitopNot(destination: K?, source: K?): Long? = ops.bitopNot(destination, source).await() + + /** + * Perform bitwise OR between strings. + * + * @param destination result key of the operation. + * @param keys operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + override suspend fun bitopOr(destination: K?, vararg keys: K?): Long? = ops.bitopOr(destination, *keys).await() + + /** + * Perform bitwise XOR between strings. + * + * @param destination result key of the operation. + * @param keys operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + override suspend fun bitopXor(destination: K?, vararg keys: K?): Long? = ops.bitopXor(destination, *keys).await() + + /** + * Decrement the integer value of a key by one. + * + * @param key the key. + * @return Long integer-reply the value of {@code key} after the decrement. + * + **/ + override suspend fun decr(key: K?): Long? = ops.decr(key).await() + + /** + * Decrement the integer value of a key by the given number. + * + * @param key the key. + * @param amount the decrement type: long. + * @return Long integer-reply the value of {@code key} after the decrement. + * + **/ + override suspend fun decrby(key: K?, amount: Long): Long? = ops.decrby(key, amount).await() + + /** + * Get the value of a key. + * + * @param key the key. + * @return V bulk-string-reply the value of {@code key}, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun get(key: K?): V? = ops.get(key).await() + + /** + * Returns the bit value at offset in the string value stored at key. + * + * @param key the key. + * @param offset the offset type: long. + * @return Long integer-reply the bit value stored at offset. + * + **/ + override suspend fun getbit(key: K?, offset: Long): Long? = ops.getbit(key, offset).await() + + /** + * Get a substring of the string stored at a key. + * + * @param key the key. + * @param start the start type: long. + * @param end the end type: long. + * @return V bulk-string-reply. + * + **/ + override suspend fun getrange(key: K?, start: Long, end: Long): V? = ops.getrange(key, start, end).await() + + /** + * Set the string value of a key and return its old value. + * + * @param key the key. + * @param value the value. + * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. + * + **/ + override suspend fun getset(key: K?, value: V?): V? = ops.getset(key, value).await() + + /** + * Increment the integer value of a key by one. + * + * @param key the key. + * @return Long integer-reply the value of {@code key} after the increment. + * + **/ + override suspend fun incr(key: K?): Long? = ops.incr(key).await() + + /** + * Increment the integer value of a key by the given amount. + * + * @param key the key. + * @param amount the increment type: long. + * @return Long integer-reply the value of {@code key} after the increment. + * + **/ + override suspend fun incrby(key: K?, amount: Long): Long? = ops.incrby(key, amount).await() + + /** + * Increment the float value of a key by the given amount. + * + * @param key the key. + * @param amount the increment type: double. + * @return Double bulk-string-reply the value of {@code key} after the increment. + * + **/ + override suspend fun incrbyfloat(key: K?, amount: Double): Double? = ops.incrbyfloat(key, amount).await() + + /** + * Get the values of all the given keys. + * + * @param keys the key. + * @return List array-reply list of values at the specified keys. + * + **/ + override suspend fun mget(vararg keys: K?): List>? = ops.mget(*keys).await() + + /** + * Stream over the values of all the given keys. + * + * @param channel the channel. + * @param keys the keys. + * @return Long array-reply list of values at the specified keys. + * + **/ + override suspend fun mget(channel: KeyValueStreamingChannel?, vararg keys: K?): Long? = ops.mget(channel, *keys).await() + + /** + * Set multiple keys to multiple values. + * + * @param map the null. + * @return String simple-string-reply always {@code OK} since {@code MSET} can't fail. + * + **/ + override suspend fun mset(map: Map?): String? = ops.mset(map).await() + + /** + * Set multiple keys to multiple values, only if none of the keys exist. + * + * @param map the null. + * @return Boolean integer-reply specifically: + * + * {@code 1} if the all the keys were set. {@code 0} if no key was set (at least one key already existed). + * + **/ + override suspend fun msetnx(map: Map?): Boolean? = ops.msetnx(map).await() + + /** + * Set the string value of a key. + * + * @param key the key. + * @param value the value. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. + * + **/ + override suspend fun set(key: K?, value: V?): String? = ops.set(key, value).await() + + /** + * Set the string value of a key. + * + * @param key the key. + * @param value the value. + * @param setArgs the setArgs. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. + * + **/ + override suspend fun set(key: K?, value: V?, setArgs: SetArgs?): String? = ops.set(key, value, setArgs).await() + + /** + * Sets or clears the bit at offset in the string value stored at key. + * + * @param key the key. + * @param offset the offset type: long. + * @param value the value type: string. + * @return Long integer-reply the original bit value stored at offset. + * + **/ + override suspend fun setbit(key: K?, offset: Long, value: Int): Long? = ops.setbit(key, offset, value).await() + + /** + * Set the value and expiration of a key. + * + * @param key the key. + * @param seconds the seconds type: long. + * @param value the value. + * @return String simple-string-reply. + * + **/ + override suspend fun setex(key: K?, seconds: Long, value: V?): String? = ops.setex(key, seconds, value).await() + + /** + * Set the value and expiration in milliseconds of a key. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param value the value. + * @return String simple-string-reply. + * + **/ + override suspend fun psetex(key: K?, milliseconds: Long, value: V?): String? = ops.psetex(key, milliseconds, value).await() + + /** + * Set the value of a key, only if the key does not exist. + * + * @param key the key. + * @param value the value. + * @return Boolean integer-reply specifically: + * + * {@code 1} if the key was set {@code 0} if the key was not set. + * + **/ + override suspend fun setnx(key: K?, value: V?): Boolean? = ops.setnx(key, value).await() + + /** + * Overwrite part of a string at key starting at the specified offset. + * + * @param key the key. + * @param offset the offset type: long. + * @param value the value. + * @return Long integer-reply the length of the string after it was modified by the command. + * + **/ + override suspend fun setrange(key: K?, offset: Long, value: V?): Long? = ops.setrange(key, offset, value).await() + + /** + * The STRALGO command implements complex algorithms that operate on strings. This method uses the LCS algorithm (longest + * common substring). + * + *
    + *
  • Without modifiers the string representing the longest common substring is returned.
  • + *
  • When {@link StrAlgoArgs#justLen() LEN} is given the command returns the length of the longest common substring.
  • + *
  • When {@link StrAlgoArgs#withIdx() IDX} is given the command returns an array with the LCS length and all the ranges + * in both the strings, start and end offset for each string, where there are matches. When + * {@link StrAlgoArgs#withMatchLen() WITHMATCHLEN} is given each array representing a match will also have the length of the + * match.
  • + *
+ * + * @param strAlgoArgs command arguments. + * @return StringMatchResult. + * @since 6.0 + * + **/ + override suspend fun stralgoLcs(strAlgoArgs: StrAlgoArgs?): StringMatchResult? = ops.stralgoLcs(strAlgoArgs).await() + + /** + * Get the length of the value stored in a key. + * + * @param key the key. + * @return Long integer-reply the length of the string at {@code key}, or {@code 0} when {@code key} does not exist. + * + **/ + override suspend fun strlen(key: K?): Long? = ops.strlen(key).await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisSuspendableAsyncCommandsImpl.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisSuspendableAsyncCommandsImpl.kt new file mode 100644 index 0000000000..29fac1c5da --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisSuspendableAsyncCommandsImpl.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2011-2020 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. + */ +@file:Suppress("unused", "UsePropertyAccessSyntax") + +package io.lettuce.core.api.coroutines.async + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.api.StatefulRedisConnection +import io.lettuce.core.api.async.RedisAsyncCommands +import io.lettuce.core.api.coroutines.* +import kotlinx.coroutines.future.await + +/** + * A complete reactive and thread-safe Redis API with 400+ Methods. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 5.0 + **/ +@ExperimentalLettuceCoroutinesApi +open class RedisSuspendableAsyncCommandsImpl( + private val ops: RedisAsyncCommands +) : RedisSuspendableCommands, + BaseRedisSuspendableCommands by BaseRedisSuspendableAsyncCommands(ops), + RedisGeoSuspendableCommands by RedisGeoSuspendableAsyncCommands(ops), + RedisHashSuspendableCommands by RedisHashSuspendableAsyncCommands(ops), + RedisHLLSuspendableCommands by RedisHLLSuspendableAsyncCommands(ops), + RedisKeySuspendableCommands by RedisKeySuspendableAsyncCommands(ops), + RedisListSuspendableCommands by RedisListSuspendableAsyncCommands(ops), + RedisScriptingSuspendableCommands by RedisScriptingSuspendableAsyncCommands(ops), + RedisServerSuspendableCommands by RedisServerSuspendableAsyncCommands(ops), + RedisSetSuspendableCommands by RedisSetSuspendableAsyncCommands(ops), + RedisSortedSetSuspendableCommands by RedisSortedSetSuspendableAsyncCommands(ops), + RedisStreamSuspendableCommands by RedisStreamSuspendableAsyncCommands(ops), + RedisStringSuspendableCommands by RedisStringSuspendableAsyncCommands(ops), + RedisTransactionalSuspendableCommands by RedisTransactionalSuspendableAsyncCommands(ops) { + + /** + * Authenticate to the server. + * + * @param password the password + * @return String simple-string-reply + */ + override suspend fun auth(password: CharSequence?): String? = ops.auth(password).await() + + /** + * Authenticate to the server with username and password. Requires Redis 6 or newer. + * + * @param username the username + * @param password the password + * @return String simple-string-reply + * @since 6.0 + */ + override suspend fun auth(username: String?, password: CharSequence?): String? = ops.auth(username, password).await() + + /** + * Change the selected database for the current connection. + * + * @param db the database number + * @return String simple-string-reply + */ + override suspend fun select(db: Int): String? = ops.select(db).await() + + /** + * Swap two Redis databases, so that immediately all the clients connected to a given DB will see the data of the other DB, + * and the other way around + * + * @param db1 the first database number + * @param db2 the second database number + * @return String simple-string-reply + */ + override suspend fun swapdb(db1: Int, db2: Int): String? = ops.swapdb(db1, db2).await() + + /** + * @return the underlying connection. + */ + override val statefulConnection: StatefulRedisConnection = ops.statefulConnection +} \ No newline at end of file diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisTransactionalSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisTransactionalSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..f33598302e --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/async/RedisTransactionalSuspendableAsyncCommands.kt @@ -0,0 +1,89 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.TransactionResult + + +/** + * Coroutine executed commands (based on async commands) for Transactions. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisTransactionalSuspendableAsyncCommands(private val ops: RedisTransactionalAsyncCommands) : RedisTransactionalSuspendableCommands { + + /** + * Discard all commands issued after MULTI. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun discard(): String? = ops.discard().await() + + /** + * Execute all commands issued after MULTI. + * + * @return List array-reply each element being the reply to each of the commands in the atomic transaction. + * + * When using {@code WATCH}, {@code EXEC} can return a {@link TransactionResult#wasDiscarded discarded + * TransactionResult}. + * @see TransactionResult#wasDiscarded + * + **/ + override suspend fun exec(): TransactionResult? = ops.exec().await() + + /** + * Mark the start of a transaction block. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun multi(): String? = ops.multi().await() + + /** + * Watch the given keys to determine execution of the MULTI/EXEC block. + * + * @param keys the key. + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun watch(vararg keys: K?): String? = ops.watch(*keys).await() + + /** + * Forget about all watched keys. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun unwatch(): String? = ops.unwatch().await() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/BaseRedisSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/BaseRedisSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..f6c3f0ae11 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/BaseRedisSuspendableReactiveCommands.kt @@ -0,0 +1,206 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.protocol.CommandArgs +import io.lettuce.core.protocol.ProtocolKeyword +import io.lettuce.core.output.CommandOutput + + +/** + * Coroutine executed commands (based on reactive commands) for basic commands. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class BaseRedisSuspendableReactiveCommands(private val ops: BaseRedisReactiveCommands) : BaseRedisSuspendableCommands { + + /** + * Post a message to a channel. + * + * @param channel the channel type: key. + * @param message the message type: value. + * @return Long integer-reply the number of clients that received the message. + * + **/ + override suspend fun publish(channel: K?, message: V?): Long? = ops.publish(channel, message).awaitFirstOrNull() + + /** + * Lists the currently *active channels*. + * + * @return List array-reply a list of active channels, optionally matching the specified pattern. + * + **/ + override suspend fun pubsubChannels(): List? = ops.pubsubChannels().collectList().awaitFirstOrNull() + + /** + * Lists the currently *active channels*. + * + * @param channel the key. + * @return List array-reply a list of active channels, optionally matching the specified pattern. + * + **/ + override suspend fun pubsubChannels(channel: K?): List? = ops.pubsubChannels(channel).collectList().awaitFirstOrNull() + + /** + * Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels. + * + * @param channels channel keys. + * @return array-reply a list of channels and number of subscribers for every channel. + * + **/ + override suspend fun pubsubNumsub(vararg channels: K?): Map? = ops.pubsubNumsub(*channels).awaitFirstOrNull() + + /** + * Returns the number of subscriptions to patterns. + * + * @return Long integer-reply the number of patterns all the clients are subscribed to. + * + **/ + override suspend fun pubsubNumpat(): Long? = ops.pubsubNumpat().awaitFirstOrNull() + + /** + * Echo the given string. + * + * @param msg the message type: value. + * @return V bulk-string-reply. + * + **/ + override suspend fun echo(msg: V?): V? = ops.echo(msg).awaitFirstOrNull() + + /** + * Return the role of the instance in the context of replication. + * + * @return List array-reply where the first element is one of master, slave, sentinel and the additional + * elements are role-specific. + * + **/ + override suspend fun role(): List? = ops.role().collectList().awaitFirstOrNull() + + /** + * Ping the server. + * + * @return String simple-string-reply. + * + **/ + override suspend fun ping(): String? = ops.ping().awaitFirstOrNull() + + /** + * Switch connection to Read-Only mode when connecting to a cluster. + * + * @return String simple-string-reply. + * + **/ + override suspend fun readOnly(): String? = ops.readOnly().awaitFirstOrNull() + + /** + * Switch connection to Read-Write mode (default) when connecting to a cluster. + * + * @return String simple-string-reply. + * + **/ + override suspend fun readWrite(): String? = ops.readWrite().awaitFirstOrNull() + + /** + * Instructs Redis to disconnect the connection. Note that if auto-reconnect is enabled then Lettuce will auto-reconnect if + * the connection was disconnected. Use {@link io.lettuce.core.api.StatefulConnection#close} to close connections and + * release resources. + * + * @return String simple-string-reply always OK. + * + **/ + override suspend fun quit(): String? = ops.quit().awaitFirstOrNull() + + /** + * Wait for replication. + * + * @param replicas minimum number of replicas. + * @param timeout timeout in milliseconds. + * @return number of replicas. + * + **/ + override suspend fun waitForReplication(replicas: Int, timeout: Long): Long? = ops.waitForReplication(replicas, timeout).awaitFirstOrNull() + + /** + * Dispatch a command to the Redis Server. Please note the command output type must fit to the command response. + * + * @param type the command, must not be {@code null}. + * @param output the command output, must not be {@code null}. + * @param response type. + * @return the command response. + * + **/ + override suspend fun dispatch(type: ProtocolKeyword?, output: CommandOutput?): T? = ops.dispatch(type, output).awaitFirstOrNull() + + /** + * Dispatch a command to the Redis Server. Please note the command output type must fit to the command response. + * + * @param type the command, must not be {@code null}. + * @param output the command output, must not be {@code null}. + * @param args the command arguments, must not be {@code null}. + * @param response type. + * @return the command response. + * + **/ + override suspend fun dispatch(type: ProtocolKeyword?, output: CommandOutput?, args: CommandArgs?): T? = ops.dispatch(type, output, args).awaitFirstOrNull() + + /** + * + * @return @code true} if the connection is open (connected and not closed). + * + **/ + override suspend fun isOpen(): Boolean = ops.isOpen() + + /** + * Reset the command state. Queued commands will be canceled and the internal state will be reset. This is useful when the + * internal state machine gets out of sync with the connection. + * + **/ + override suspend fun reset(): Unit? = ops.reset() + + /** + * Disable or enable auto-flush behavior. Default is {@code true}. If autoFlushCommands is disabled, multiple commands can + * be issued without writing them actually to the transport. Commands are buffered until a {@link #flushCommands()} is + * issued. After calling {@link #flushCommands()} commands are sent to the transport and executed by Redis. + * + * @param autoFlush state of autoFlush. + * + **/ + override suspend fun setAutoFlushCommands(autoFlush: Boolean): Unit? = ops.setAutoFlushCommands(autoFlush) + + /** + * Flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to + * achieve batching. No-op if channel is not connected. + * + **/ + override suspend fun flushCommands(): Unit? = ops.flushCommands() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisGeoSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisGeoSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..c52ad6e6a5 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisGeoSuspendableReactiveCommands.kt @@ -0,0 +1,185 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.* + + +/** + * Coroutine executed commands (based on reactive commands) for the Geo-API. + * + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisGeoSuspendableReactiveCommands(private val ops: RedisGeoReactiveCommands) : RedisGeoSuspendableCommands { + + /** + * Single geo add. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param member the member to add. + * @return Long integer-reply the number of elements that were added to the set. + * + **/ + override suspend fun geoadd(key: K?, longitude: Double, latitude: Double, member: V?): Long? = ops.geoadd(key, longitude, latitude, member).awaitFirstOrNull() + + /** + * Multi geo add. + * + * @param key the key of the geo set. + * @param lngLatMember triplets of double longitude, double latitude and V member. + * @return Long integer-reply the number of elements that were added to the set. + * + **/ + override suspend fun geoadd(key: K?, vararg lngLatMember: Any?): Long? = ops.geoadd(key, *lngLatMember).awaitFirstOrNull() + + /** + * Retrieve Geohash strings representing the position of one or more elements in a sorted set value representing a + * geospatial index. + * + * @param key the key of the geo set. + * @param members the members. + * @return bulk reply Geohash strings in the order of {@code members}. Returns {@code null} if a member is not found. + * + **/ + override suspend fun geohash(key: K?, vararg members: V?): List>? = ops.geohash(key, *members).collectList().awaitFirstOrNull() + + /** + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param distance radius distance. + * @param unit distance unit. + * @return bulk reply. + * + **/ + override suspend fun georadius(key: K?, longitude: Double, latitude: Double, distance: Double, unit: GeoArgs.Unit?): Set? = ops.georadius(key, longitude, latitude, distance, unit).collectList().awaitFirstOrNull()?.toSet() + + /** + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param distance radius distance. + * @param unit distance unit. + * @param geoArgs args to control the result. + * @return nested multi-bulk reply. The {@link GeoWithin} contains only fields which were requested by {@link GeoArgs}. + * + **/ + override suspend fun georadius(key: K?, longitude: Double, latitude: Double, distance: Double, unit: GeoArgs.Unit?, geoArgs: GeoArgs?): List>? = ops.georadius(key, longitude, latitude, distance, unit, geoArgs).collectList().awaitFirstOrNull() + + /** + * Perform a {@link #georadius(Object, double, double, double, GeoArgs.Unit, GeoArgs)} query and store the results in a + * sorted set. + * + * @param key the key of the geo set. + * @param longitude the longitude coordinate according to WGS84. + * @param latitude the latitude coordinate according to WGS84. + * @param distance radius distance. + * @param unit distance unit. + * @param geoRadiusStoreArgs args to store either the resulting elements with their distance or the resulting elements with + * their locations a sorted set. + * @return Long integer-reply the number of elements in the result. + * + **/ + override suspend fun georadius(key: K?, longitude: Double, latitude: Double, distance: Double, unit: GeoArgs.Unit?, geoRadiusStoreArgs: GeoRadiusStoreArgs?): Long? = ops.georadius(key, longitude, latitude, distance, unit, geoRadiusStoreArgs).awaitFirstOrNull() + + /** + * Retrieve members selected by distance with the center of {@code member}. The member itself is always contained in the + * results. + * + * @param key the key of the geo set. + * @param member reference member. + * @param distance radius distance. + * @param unit distance unit. + * @return set of members. + * + **/ + override suspend fun georadiusbymember(key: K?, member: V?, distance: Double, unit: GeoArgs.Unit?): Set? = ops.georadiusbymember(key, member, distance, unit).collectList().awaitFirstOrNull()?.toSet() + + /** + * Retrieve members selected by distance with the center of {@code member}. The member itself is always contained in the + * results. + * + * @param key the key of the geo set. + * @param member reference member. + * @param distance radius distance. + * @param unit distance unit. + * @param geoArgs args to control the result. + * @return nested multi-bulk reply. The {@link GeoWithin} contains only fields which were requested by {@link GeoArgs}. + * + **/ + override suspend fun georadiusbymember(key: K?, member: V?, distance: Double, unit: GeoArgs.Unit?, geoArgs: GeoArgs?): List>? = ops.georadiusbymember(key, member, distance, unit, geoArgs).collectList().awaitFirstOrNull() + + /** + * Perform a {@link #georadiusbymember(Object, Object, double, GeoArgs.Unit, GeoArgs)} query and store the results in a + * sorted set. + * + * @param key the key of the geo set. + * @param member reference member. + * @param distance radius distance. + * @param unit distance unit. + * @param geoRadiusStoreArgs args to store either the resulting elements with their distance or the resulting elements with + * their locations a sorted set. + * @return Long integer-reply the number of elements in the result. + * + **/ + override suspend fun georadiusbymember(key: K?, member: V?, distance: Double, unit: GeoArgs.Unit?, geoRadiusStoreArgs: GeoRadiusStoreArgs?): Long? = ops.georadiusbymember(key, member, distance, unit, geoRadiusStoreArgs).awaitFirstOrNull() + + /** + * Get geo coordinates for the {@code members}. + * + * @param key the key of the geo set. + * @param members the members. + * @return a list of {@link GeoCoordinates}s representing the x,y position of each element specified in the arguments. For + * missing elements {@code null} is returned. + * + **/ + override suspend fun geopos(key: K?, vararg members: V?): List? = ops.geopos(key, *members).map { it.value }.collectList().awaitFirstOrNull() + + /** + * Retrieve distance between points {@code from} and {@code to}. If one or more elements are missing {@code null} is + * returned. Default in meters by, otherwise according to {@code unit} + * + * @param key the key of the geo set. + * @param from from member. + * @param to to member. + * @param unit distance unit. + * @return distance between points {@code from} and {@code to}. If one or more elements are missing {@code null} is + * returned. + * + **/ + override suspend fun geodist(key: K?, from: V?, to: V?, unit: GeoArgs.Unit?): Double? = ops.geodist(key, from, to, unit).awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisHLLSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisHLLSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..2bd7a19acf --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisHLLSuspendableReactiveCommands.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi + + +/** + * Coroutine executed commands (based on reactive commands) for HyperLogLog (PF* commands). + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisHLLSuspendableReactiveCommands(private val ops: RedisHLLReactiveCommands) : RedisHLLSuspendableCommands { + + /** + * Adds the specified elements to the specified HyperLogLog. + * + * @param key the key. + * @param values the values. + * @return Long integer-reply specifically: + * + * 1 if at least 1 HyperLogLog internal register was altered. 0 otherwise. + * + **/ + override suspend fun pfadd(key: K?, vararg values: V?): Long? = ops.pfadd(key, *values).awaitFirstOrNull() + + /** + * Merge N different HyperLogLogs into a single one. + * + * @param destkey the destination key. + * @param sourcekeys the source key. + * @return String simple-string-reply The command just returns {@code OK}. + * + **/ + override suspend fun pfmerge(destkey: K?, vararg sourcekeys: K?): String? = ops.pfmerge(destkey, *sourcekeys).awaitFirstOrNull() + + /** + * Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s). + * + * @param keys the keys. + * @return Long integer-reply specifically: + * + * The approximated number of unique elements observed via {@code PFADD}. + * + **/ + override suspend fun pfcount(vararg keys: K?): Long? = ops.pfcount(*keys).awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisHashSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisHashSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..2893f322a3 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisHashSuspendableReactiveCommands.kt @@ -0,0 +1,336 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.* +import io.lettuce.core.output.KeyStreamingChannel +import io.lettuce.core.output.KeyValueStreamingChannel +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on reactive commands) for Hashes (Key-Value pairs). + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisHashSuspendableReactiveCommands(private val ops: RedisHashReactiveCommands) : RedisHashSuspendableCommands { + + /** + * Delete one or more hash fields. + * + * @param key the key. + * @param fields the field type: key. + * @return Long integer-reply the number of fields that were removed from the hash, not including specified but non existing + * fields. + * + **/ + override suspend fun hdel(key: K?, vararg fields: K?): Long? = ops.hdel(key, *fields).awaitFirstOrNull() + + /** + * Determine if a hash field exists. + * + * @param key the key. + * @param field the field type: key. + * @return Boolean integer-reply specifically: + * + * {@code true} if the hash contains {@code field}. {@code false} if the hash does not contain {@code field}, or + * {@code key} does not exist. + * + **/ + override suspend fun hexists(key: K?, field: K?): Boolean? = ops.hexists(key, field).awaitFirstOrNull() + + /** + * Get the value of a hash field. + * + * @param key the key. + * @param field the field type: key. + * @return V bulk-string-reply the value associated with {@code field}, or {@code null} when {@code field} is not present in + * the hash or {@code key} does not exist. + * + **/ + override suspend fun hget(key: K?, field: K?): V? = ops.hget(key, field).awaitFirstOrNull() + + /** + * Increment the integer value of a hash field by the given number. + * + * @param key the key. + * @param field the field type: key. + * @param amount the increment type: long. + * @return Long integer-reply the value at {@code field} after the increment operation. + * + **/ + override suspend fun hincrby(key: K?, field: K?, amount: Long): Long? = ops.hincrby(key, field, amount).awaitFirstOrNull() + + /** + * Increment the float value of a hash field by the given amount. + * + * @param key the key. + * @param field the field type: key. + * @param amount the increment type: double. + * @return Double bulk-string-reply the value of {@code field} after the increment. + * + **/ + override suspend fun hincrbyfloat(key: K?, field: K?, amount: Double): Double? = ops.hincrbyfloat(key, field, amount).awaitFirstOrNull() + + /** + * Get all the fields and values in a hash. + * + * @param key the key. + * @return Map array-reply list of fields and their values stored in the hash, or an empty list when {@code key} + * does not exist. + * + **/ + override suspend fun hgetall(key: K?): Map? = ops.hgetall(key).awaitFirstOrNull() + + /** + * Stream over all the fields and values in a hash. + * + * @param channel the channel. + * @param key the key. + * @return Long count of the keys. + * + **/ + override suspend fun hgetall(channel: KeyValueStreamingChannel?, key: K?): Long? = ops.hgetall(channel, key).awaitFirstOrNull() + + /** + * Get all the fields in a hash. + * + * @param key the key. + * @return List array-reply list of fields in the hash, or an empty list when {@code key} does not exist. + * + **/ + override suspend fun hkeys(key: K?): List? = ops.hkeys(key).collectList().awaitFirstOrNull() + + /** + * Stream over all the fields in a hash. + * + * @param channel the channel. + * @param key the key. + * @return Long count of the keys. + * + **/ + override suspend fun hkeys(channel: KeyStreamingChannel?, key: K?): Long? = ops.hkeys(channel, key).awaitFirstOrNull() + + /** + * Get the number of fields in a hash. + * + * @param key the key. + * @return Long integer-reply number of fields in the hash, or {@code 0} when {@code key} does not exist. + * + **/ + override suspend fun hlen(key: K?): Long? = ops.hlen(key).awaitFirstOrNull() + + /** + * Get the values of all the given hash fields. + * + * @param key the key. + * @param fields the field type: key. + * @return List array-reply list of values associated with the given fields, in the same. + * + **/ + override suspend fun hmget(key: K?, vararg fields: K?): List>? = ops.hmget(key, *fields).collectList().awaitFirstOrNull() + + /** + * Stream over the values of all the given hash fields. + * + * @param channel the channel. + * @param key the key. + * @param fields the fields. + * @return Long count of the keys. + * + **/ + override suspend fun hmget(channel: KeyValueStreamingChannel?, key: K?, vararg fields: K?): Long? = ops.hmget(channel, key, *fields).awaitFirstOrNull() + + /** + * Set multiple hash fields to multiple values. + * + * @param key the key. + * @param map the null. + * @return String simple-string-reply. + * + **/ + override suspend fun hmset(key: K?, map: Map?): String? = ops.hmset(key, map).awaitFirstOrNull() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @return MapScanCursor map scan cursor. + * + **/ + override suspend fun hscan(key: K?): MapScanCursor? = ops.hscan(key).awaitFirstOrNull() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @param scanArgs scan arguments. + * @return MapScanCursor map scan cursor. + * + **/ + override suspend fun hscan(key: K?, scanArgs: ScanArgs?): MapScanCursor? = ops.hscan(key, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return MapScanCursor map scan cursor. + * + **/ + override suspend fun hscan(key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): MapScanCursor? = ops.hscan(key, scanCursor, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return MapScanCursor map scan cursor. + * + **/ + override suspend fun hscan(key: K?, scanCursor: ScanCursor?): MapScanCursor? = ops.hscan(key, scanCursor).awaitFirstOrNull() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?): StreamScanCursor? = ops.hscan(channel, key).awaitFirstOrNull() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?, scanArgs: ScanArgs?): StreamScanCursor? = ops.hscan(channel, key, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? = ops.hscan(channel, key, scanCursor, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate hash fields and associated values. + * + * @param channel streaming channel that receives a call for every key-value pair. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun hscan(channel: KeyValueStreamingChannel?, key: K?, scanCursor: ScanCursor?): StreamScanCursor? = ops.hscan(channel, key, scanCursor).awaitFirstOrNull() + + /** + * Set the string value of a hash field. + * + * @param key the key. + * @param field the field type: key. + * @param value the value. + * @return Boolean integer-reply specifically: + * + * {@code true} if {@code field} is a new field in the hash and {@code value} was set. {@code false} if + * {@code field} already exists in the hash and the value was updated. + * + **/ + override suspend fun hset(key: K?, field: K?, value: V?): Boolean? = ops.hset(key, field, value).awaitFirstOrNull() + + /** + * Set multiple hash fields to multiple values. + * + * @param key the key of the hash. + * @param map the field/value pairs to update. + * @return Long integer-reply: the number of fields that were added. + * @since 5.3 + * + **/ + override suspend fun hset(key: K?, map: Map?): Long? = ops.hset(key, map).awaitFirstOrNull() + + /** + * Set the value of a hash field, only if the field does not exist. + * + * @param key the key. + * @param field the field type: key. + * @param value the value. + * @return Boolean integer-reply specifically: + * + * {@code 1} if {@code field} is a new field in the hash and {@code value} was set. {@code 0} if {@code field} + * already exists in the hash and no operation was performed. + * + **/ + override suspend fun hsetnx(key: K?, field: K?, value: V?): Boolean? = ops.hsetnx(key, field, value).awaitFirstOrNull() + + /** + * Get the string length of the field value in a hash. + * + * @param key the key. + * @param field the field type: key. + * @return Long integer-reply the string length of the {@code field} value, or {@code 0} when {@code field} is not present + * in the hash or {@code key} does not exist at all. + * + **/ + override suspend fun hstrlen(key: K?, field: K?): Long? = ops.hstrlen(key, field).awaitFirstOrNull() + + /** + * Get all the values in a hash. + * + * @param key the key. + * @return List array-reply list of values in the hash, or an empty list when {@code key} does not exist. + * + **/ + override suspend fun hvals(key: K?): List? = ops.hvals(key).collectList().awaitFirstOrNull() + + /** + * Stream over all the values in a hash. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @return Long count of the keys. + * + **/ + override suspend fun hvals(channel: ValueStreamingChannel?, key: K?): Long? = ops.hvals(channel, key).awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisKeySuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisKeySuspendableReactiveCommands.kt new file mode 100644 index 0000000000..1d104a1f42 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisKeySuspendableReactiveCommands.kt @@ -0,0 +1,471 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import java.util.Date +import io.lettuce.core.* +import io.lettuce.core.output.KeyStreamingChannel +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on reactive commands) for Keys (Key manipulation/querying). + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisKeySuspendableReactiveCommands(private val ops: RedisKeyReactiveCommands) : RedisKeySuspendableCommands { + + /** + * Delete one or more keys. + * + * @param keys the keys. + * @return Long integer-reply The number of keys that were removed. + * + **/ + override suspend fun del(vararg keys: K?): Long? = ops.del(*keys).awaitFirstOrNull() + + /** + * Unlink one or more keys (non blocking DEL). + * + * @param keys the keys. + * @return Long integer-reply The number of keys that were removed. + * + **/ + override suspend fun unlink(vararg keys: K?): Long? = ops.unlink(*keys).awaitFirstOrNull() + + /** + * Return a serialized version of the value stored at the specified key. + * + * @param key the key. + * @return byte[] bulk-string-reply the serialized value. + * + **/ + override suspend fun dump(key: K?): ByteArray? = ops.dump(key).awaitFirstOrNull() + + /** + * Determine how many keys exist. + * + * @param keys the keys. + * @return Long integer-reply specifically: Number of existing keys. + * + **/ + override suspend fun exists(vararg keys: K?): Long? = ops.exists(*keys).awaitFirstOrNull() + + /** + * Set a key's time to live in seconds. + * + * @param key the key. + * @param seconds the seconds type: long. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set. + * + **/ + override suspend fun expire(key: K?, seconds: Long): Boolean? = ops.expire(key, seconds).awaitFirstOrNull() + + /** + * Set the expiration for a key as a UNIX timestamp. + * + * @param key the key. + * @param timestamp the timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + override suspend fun expireat(key: K?, timestamp: Date?): Boolean? = ops.expireat(key, timestamp).awaitFirstOrNull() + + /** + * Set the expiration for a key as a UNIX timestamp. + * + * @param key the key. + * @param timestamp the timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + override suspend fun expireat(key: K?, timestamp: Long): Boolean? = ops.expireat(key, timestamp).awaitFirstOrNull() + + /** + * Find all keys matching the given pattern. + * + * @param pattern the pattern type: patternkey (pattern). + * @return List array-reply list of keys matching {@code pattern}. + * + **/ + override suspend fun keys(pattern: K?): List? = ops.keys(pattern).collectList().awaitFirstOrNull() + + /** + * Find all keys matching the given pattern. + * + * @param channel the channel. + * @param pattern the pattern. + * @return Long array-reply list of keys matching {@code pattern}. + * + **/ + override suspend fun keys(channel: KeyStreamingChannel?, pattern: K?): Long? = ops.keys(channel, pattern).awaitFirstOrNull() + + /** + * Atomically transfer a key from a Redis instance to another one. + * + * @param host the host. + * @param port the port. + * @param key the key. + * @param db the database. + * @param timeout the timeout in milliseconds. + * @return String simple-string-reply The command returns OK on success. + * + **/ + override suspend fun migrate(host: String?, port: Int, key: K?, db: Int, timeout: Long): String? = ops.migrate(host, port, key, db, timeout).awaitFirstOrNull() + + /** + * Atomically transfer one or more keys from a Redis instance to another one. + * + * @param host the host. + * @param port the port. + * @param db the database. + * @param timeout the timeout in milliseconds. + * @param migrateArgs migrate args that allow to configure further options. + * @return String simple-string-reply The command returns OK on success. + * + **/ + override suspend fun migrate(host: String?, port: Int, db: Int, timeout: Long, migrateArgs: MigrateArgs?): String? = ops.migrate(host, port, db, timeout, migrateArgs).awaitFirstOrNull() + + /** + * Move a key to another database. + * + * @param key the key. + * @param db the db type: long. + * @return Boolean integer-reply specifically:. + * + **/ + override suspend fun move(key: K?, db: Int): Boolean? = ops.move(key, db).awaitFirstOrNull() + + /** + * returns the kind of internal representation used in order to store the value associated with a key. + * + * @param key the key. + * @return String. + * + **/ + override suspend fun objectEncoding(key: K?): String? = ops.objectEncoding(key).awaitFirstOrNull() + + /** + * returns the number of seconds since the object stored at the specified key is idle (not requested by read or write + * operations). + * + * @param key the key. + * @return number of seconds since the object stored at the specified key is idle. + * + **/ + override suspend fun objectIdletime(key: K?): Long? = ops.objectIdletime(key).awaitFirstOrNull() + + /** + * returns the number of references of the value associated with the specified key. + * + * @param key the key. + * @return Long. + * + **/ + override suspend fun objectRefcount(key: K?): Long? = ops.objectRefcount(key).awaitFirstOrNull() + + /** + * Remove the expiration from a key. + * + * @param key the key. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was removed. {@code false} if {@code key} does not exist or does not have an + * associated timeout. + * + **/ + override suspend fun persist(key: K?): Boolean? = ops.persist(key).awaitFirstOrNull() + + /** + * Set a key's time to live in milliseconds. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @return integer-reply, specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set. + * + **/ + override suspend fun pexpire(key: K?, milliseconds: Long): Boolean? = ops.pexpire(key, milliseconds).awaitFirstOrNull() + + /** + * Set the expiration for a key as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + override suspend fun pexpireat(key: K?, timestamp: Date?): Boolean? = ops.pexpireat(key, timestamp).awaitFirstOrNull() + + /** + * Set the expiration for a key as a UNIX timestamp specified in milliseconds. + * + * @param key the key. + * @param timestamp the milliseconds-timestamp type: posix time. + * @return Boolean integer-reply specifically: + * + * {@code true} if the timeout was set. {@code false} if {@code key} does not exist or the timeout could not be set + * (see: {@code EXPIRE}). + * + **/ + override suspend fun pexpireat(key: K?, timestamp: Long): Boolean? = ops.pexpireat(key, timestamp).awaitFirstOrNull() + + /** + * Get the time to live for a key in milliseconds. + * + * @param key the key. + * @return Long integer-reply TTL in milliseconds, or a negative value in order to signal an error (see the description + * above). + * + **/ + override suspend fun pttl(key: K?): Long? = ops.pttl(key).awaitFirstOrNull() + + /** + * Return a random key from the keyspace. + * + * @return K bulk-string-reply the random key, or {@code null} when the database is empty. + * + **/ + override suspend fun randomkey(): K? = ops.randomkey().awaitFirstOrNull() + + /** + * Rename a key. + * + * @param key the key. + * @param newKey the newkey type: key. + * @return String simple-string-reply. + * + **/ + override suspend fun rename(key: K?, newKey: K?): String? = ops.rename(key, newKey).awaitFirstOrNull() + + /** + * Rename a key, only if the new key does not exist. + * + * @param key the key. + * @param newKey the newkey type: key. + * @return Boolean integer-reply specifically: + * + * {@code true} if {@code key} was renamed to {@code newkey}. {@code false} if {@code newkey} already exists. + * + **/ + override suspend fun renamenx(key: K?, newKey: K?): Boolean? = ops.renamenx(key, newKey).awaitFirstOrNull() + + /** + * Create a key using the provided serialized value, previously obtained using DUMP. + * + * @param key the key. + * @param ttl the ttl type: long. + * @param value the serialized-value type: string. + * @return String simple-string-reply The command returns OK on success. + * + **/ + override suspend fun restore(key: K?, ttl: Long, value: ByteArray?): String? = ops.restore(key, ttl, value).awaitFirstOrNull() + + /** + * Create a key using the provided serialized value, previously obtained using DUMP. + * + * @param key the key. + * @param value the serialized-value type: string. + * @param args the {@link RestoreArgs}, must not be {@code null}. + * @return String simple-string-reply The command returns OK on success. + * @since 5.1 + * + **/ + override suspend fun restore(key: K?, value: ByteArray?, args: RestoreArgs?): String? = ops.restore(key, value, args).awaitFirstOrNull() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param key the key. + * @return List array-reply list of sorted elements. + * + **/ + override suspend fun sort(key: K?): List? = ops.sort(key).collectList().awaitFirstOrNull() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @return Long number of values. + * + **/ + override suspend fun sort(channel: ValueStreamingChannel?, key: K?): Long? = ops.sort(channel, key).awaitFirstOrNull() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param key the key. + * @param sortArgs sort arguments. + * @return List array-reply list of sorted elements. + * + **/ + override suspend fun sort(key: K?, sortArgs: SortArgs?): List? = ops.sort(key, sortArgs).collectList().awaitFirstOrNull() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param sortArgs sort arguments. + * @return Long number of values. + * + **/ + override suspend fun sort(channel: ValueStreamingChannel?, key: K?, sortArgs: SortArgs?): Long? = ops.sort(channel, key, sortArgs).awaitFirstOrNull() + + /** + * Sort the elements in a list, set or sorted set. + * + * @param key the key. + * @param sortArgs sort arguments. + * @param destination the destination key to store sort results. + * @return Long number of values. + * + **/ + override suspend fun sortStore(key: K?, sortArgs: SortArgs?, destination: K?): Long? = ops.sortStore(key, sortArgs, destination).awaitFirstOrNull() + + /** + * Touch one or more keys. Touch sets the last accessed time for a key. Non-exsitent keys wont get created. + * + * @param keys the keys. + * @return Long integer-reply the number of found keys. + * + **/ + override suspend fun touch(vararg keys: K?): Long? = ops.touch(*keys).awaitFirstOrNull() + + /** + * Get the time to live for a key. + * + * @param key the key. + * @return Long integer-reply TTL in seconds, or a negative value in order to signal an error (see the description above). + * + **/ + override suspend fun ttl(key: K?): Long? = ops.ttl(key).awaitFirstOrNull() + + /** + * Determine the type stored at key. + * + * @param key the key. + * @return String simple-string-reply type of {@code key}, or {@code none} when {@code key} does not exist. + * + **/ + override suspend fun type(key: K?): String? = ops.type(key).awaitFirstOrNull() + + /** + * Incrementally iterate the keys space. + * + * @return KeyScanCursor scan cursor. + * + **/ + override suspend fun scan(): KeyScanCursor? = ops.scan().awaitFirstOrNull() + + /** + * Incrementally iterate the keys space. + * + * @param scanArgs scan arguments. + * @return KeyScanCursor scan cursor. + * + **/ + override suspend fun scan(scanArgs: ScanArgs?): KeyScanCursor? = ops.scan(scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate the keys space. + * + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return KeyScanCursor scan cursor. + * + **/ + override suspend fun scan(scanCursor: ScanCursor?, scanArgs: ScanArgs?): KeyScanCursor? = ops.scan(scanCursor, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate the keys space. + * + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return KeyScanCursor scan cursor. + * + **/ + override suspend fun scan(scanCursor: ScanCursor?): KeyScanCursor? = ops.scan(scanCursor).awaitFirstOrNull() + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun scan(channel: KeyStreamingChannel?): StreamScanCursor? = ops.scan(channel).awaitFirstOrNull() + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun scan(channel: KeyStreamingChannel?, scanArgs: ScanArgs?): StreamScanCursor? = ops.scan(channel, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun scan(channel: KeyStreamingChannel?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? = ops.scan(channel, scanCursor, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate the keys space. + * + * @param channel streaming channel that receives a call for every key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun scan(channel: KeyStreamingChannel?, scanCursor: ScanCursor?): StreamScanCursor? = ops.scan(channel, scanCursor).awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisListSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisListSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..60159ac84a --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisListSuspendableReactiveCommands.kt @@ -0,0 +1,304 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.KeyValue +import io.lettuce.core.LPosArgs +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on reactive commands) for Lists. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisListSuspendableReactiveCommands(private val ops: RedisListReactiveCommands) : RedisListSuspendableCommands { + + /** + * Remove and get the first element in a list, or block until one is available. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue array-reply specifically: + * + * A {@code null} multi-bulk when no element could be popped and the timeout expired. A two-element multi-bulk with + * the first element being the name of the key where an element was popped and the second element being the value of + * the popped element. + * + **/ + override suspend fun blpop(timeout: Long, vararg keys: K?): KeyValue? = ops.blpop(timeout, *keys).awaitFirstOrNull() + + /** + * Remove and get the last element in a list, or block until one is available. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue array-reply specifically: + * + * A {@code null} multi-bulk when no element could be popped and the timeout expired. A two-element multi-bulk with + * the first element being the name of the key where an element was popped and the second element being the value of + * the popped element. + * + **/ + override suspend fun brpop(timeout: Long, vararg keys: K?): KeyValue? = ops.brpop(timeout, *keys).awaitFirstOrNull() + + /** + * Pop a value from a list, push it to another list and return it; or block until one is available. + * + * @param timeout the timeout in seconds. + * @param source the source key. + * @param destination the destination type: key. + * @return V bulk-string-reply the element being popped from {@code source} and pushed to {@code destination}. If + * {@code timeout} is reached, a. + * + **/ + override suspend fun brpoplpush(timeout: Long, source: K?, destination: K?): V? = ops.brpoplpush(timeout, source, destination).awaitFirstOrNull() + + /** + * Get an element from a list by its index. + * + * @param key the key. + * @param index the index type: long. + * @return V bulk-string-reply the requested element, or {@code null} when {@code index} is out of range. + * + **/ + override suspend fun lindex(key: K?, index: Long): V? = ops.lindex(key, index).awaitFirstOrNull() + + /** + * Insert an element before or after another element in a list. + * + * @param key the key. + * @param before the before. + * @param pivot the pivot. + * @param value the value. + * @return Long integer-reply the length of the list after the insert operation, or {@code -1} when the value {@code pivot} + * was not found. + * + **/ + override suspend fun linsert(key: K?, before: Boolean, pivot: V?, value: V?): Long? = ops.linsert(key, before, pivot, value).awaitFirstOrNull() + + /** + * Get the length of a list. + * + * @param key the key. + * @return Long integer-reply the length of the list at {@code key}. + * + **/ + override suspend fun llen(key: K?): Long? = ops.llen(key).awaitFirstOrNull() + + /** + * Remove and get the first element in a list. + * + * @param key the key. + * @return V bulk-string-reply the value of the first element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun lpop(key: K?): V? = ops.lpop(key).awaitFirstOrNull() + + /** + * Return the index of matching elements inside a Redis list. By default, when no options are given, it will scan the list + * from head to tail, looking for the first match of "element". If the element is found, its index (the zero-based position + * in the list) is returned. Otherwise, if no match is found, {@code null} is returned. The returned elements indexes are + * always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is {@code 0}, + * and so forth. + * + * @param key the key. + * @param value the element to search for. + * @return V integer-reply representing the matching element, or null if there is no match. + * @since 5.3.2 + * + **/ + override suspend fun lpos(key: K?, value: V?): Long? = ops.lpos(key, value).awaitFirstOrNull() + + /** + * Return the index of matching elements inside a Redis list. By default, when no options are given, it will scan the list + * from head to tail, looking for the first match of "element". If the element is found, its index (the zero-based position + * in the list) is returned. Otherwise, if no match is found, {@code null} is returned. The returned elements indexes are + * always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is {@code 0}, + * and so forth. + * + * @param key the key. + * @param value the element to search for. + * @param args command arguments to configure{@code FIRST} and {@code MAXLEN} options. + * @return V integer-reply representing the matching element, or null if there is no match. + * @since 5.3.2 + * + **/ + override suspend fun lpos(key: K?, value: V?, args: LPosArgs?): Long? = ops.lpos(key, value, args).awaitFirstOrNull() + + /** + * Return the index of matching elements inside a Redis list using the {@code COUNT} option. By default, when no options are + * given, it will scan the list from head to tail, looking for the first match of "element". The returned elements indexes + * are always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is + * {@code 0}, and so forth. + * + * @param key the key. + * @param value the element to search for. + * @param count limit the number of matches. + * @return V integer-reply representing the matching elements, or empty if there is no match. + * @since 5.3.2 + * + **/ + override suspend fun lpos(key: K?, value: V?, count: Int): List? = ops.lpos(key, value, count).collectList().awaitFirstOrNull() + + /** + * Return the index of matching elements inside a Redis list using the {@code COUNT} option. By default, when no options are + * given, it will scan the list from head to tail, looking for the first match of "element". The returned elements indexes + * are always referring to what {@link #lindex(java.lang.Object, long)} would return. So first element from head is + * {@code 0}, and so forth. + * + * @param key the key. + * @param value the element to search for. + * @param count limit the number of matches. + * @param args command arguments to configure{@code FIRST} and {@code MAXLEN} options. + * @return V integer-reply representing the matching elements, or empty if there is no match. + * @since 5.3.2 + * + **/ + override suspend fun lpos(key: K?, value: V?, count: Int, args: LPosArgs?): List? = ops.lpos(key, value, count, args).collectList().awaitFirstOrNull() + + /** + * Prepend one or multiple values to a list. + * + * @param key the key. + * @param values the value. + * @return Long integer-reply the length of the list after the push operations. + * + **/ + override suspend fun lpush(key: K?, vararg values: V?): Long? = ops.lpush(key, *values).awaitFirstOrNull() + + /** + * Prepend values to a list, only if the list exists. + * + * @param key the key. + * @param values the values. + * @return Long integer-reply the length of the list after the push operation. + * + **/ + override suspend fun lpushx(key: K?, vararg values: V?): Long? = ops.lpushx(key, *values).awaitFirstOrNull() + + /** + * Get a range of elements from a list. + * + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun lrange(key: K?, start: Long, stop: Long): List? = ops.lrange(key, start, stop).collectList().awaitFirstOrNull() + + /** + * Get a range of elements from a list. + * + * @param channel the channel. + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun lrange(channel: ValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.lrange(channel, key, start, stop).awaitFirstOrNull() + + /** + * Remove elements from a list. + * + * @param key the key. + * @param count the count type: long. + * @param value the value. + * @return Long integer-reply the number of removed elements. + * + **/ + override suspend fun lrem(key: K?, count: Long, value: V?): Long? = ops.lrem(key, count, value).awaitFirstOrNull() + + /** + * Set the value of an element in a list by its index. + * + * @param key the key. + * @param index the index type: long. + * @param value the value. + * @return String simple-string-reply. + * + **/ + override suspend fun lset(key: K?, index: Long, value: V?): String? = ops.lset(key, index, value).awaitFirstOrNull() + + /** + * Trim a list to the specified range. + * + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return String simple-string-reply. + * + **/ + override suspend fun ltrim(key: K?, start: Long, stop: Long): String? = ops.ltrim(key, start, stop).awaitFirstOrNull() + + /** + * Remove and get the last element in a list. + * + * @param key the key. + * @return V bulk-string-reply the value of the last element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun rpop(key: K?): V? = ops.rpop(key).awaitFirstOrNull() + + /** + * Remove the last element in a list, append it to another list and return it. + * + * @param source the source key. + * @param destination the destination type: key. + * @return V bulk-string-reply the element being popped and pushed. + * + **/ + override suspend fun rpoplpush(source: K?, destination: K?): V? = ops.rpoplpush(source, destination).awaitFirstOrNull() + + /** + * Append one or multiple values to a list. + * + * @param key the key. + * @param values the value. + * @return Long integer-reply the length of the list after the push operation. + * + **/ + override suspend fun rpush(key: K?, vararg values: V?): Long? = ops.rpush(key, *values).awaitFirstOrNull() + + /** + * Append values to a list, only if the list exists. + * + * @param key the key. + * @param values the values. + * @return Long integer-reply the length of the list after the push operation. + * + **/ + override suspend fun rpushx(key: K?, vararg values: V?): Long? = ops.rpushx(key, *values).awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisScriptingSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisScriptingSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..cfe3115aac --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisScriptingSuspendableReactiveCommands.kt @@ -0,0 +1,189 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.ScriptOutputType + + +/** + * Coroutine executed commands (based on reactive commands) for Scripting. {@link java.lang.String Lua scripts} are encoded by using the configured + * {@link io.lettuce.core.ClientOptions#getScriptCharset() charset}. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisScriptingSuspendableReactiveCommands(private val ops: RedisScriptingReactiveCommands) : RedisScriptingSuspendableCommands { + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type output type. + * @param keys key names. + * @param expected return type. + * @return script result. + * + **/ + override suspend fun eval(script: String?, type: ScriptOutputType?, vararg keys: K?): T? = ops.eval(script, type, *keys).awaitFirstOrNull() + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type output type. + * @param keys key names. + * @param expected return type. + * @return script result. + * @since 6.0 + * + **/ + override suspend fun eval(script: ByteArray?, type: ScriptOutputType?, vararg keys: K?): T? = ops.eval(script, type, *keys).awaitFirstOrNull() + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type the type. + * @param keys the keys. + * @param values the values. + * @param expected return type. + * @return script result. + * + **/ + override suspend fun eval(script: String?, type: ScriptOutputType?, keys: Array?, vararg values: V?): T? = ops.eval(script, type, keys, *values).awaitFirstOrNull() + + /** + * Execute a Lua script server side. + * + * @param script Lua 5.1 script. + * @param type the type. + * @param keys the keys. + * @param values the values. + * @param expected return type. + * @return script result. + * @since 6.0 + * + **/ + override suspend fun eval(script: ByteArray?, type: ScriptOutputType?, keys: Array?, vararg values: V?): T? = ops.eval(script, type, keys, *values).awaitFirstOrNull() + + /** + * Evaluates a script cached on the server side by its SHA1 digest. + * + * @param digest SHA1 of the script. + * @param type the type. + * @param keys the keys. + * @param expected return type. + * @return script result. + * + **/ + override suspend fun evalsha(digest: String?, type: ScriptOutputType?, vararg keys: K?): T? = ops.evalsha(digest, type, *keys).awaitFirstOrNull() + + /** + * Execute a Lua script server side. + * + * @param digest SHA1 of the script. + * @param type the type. + * @param keys the keys. + * @param values the values. + * @param expected return type. + * @return script result. + * + **/ + override suspend fun evalsha(digest: String?, type: ScriptOutputType?, keys: Array?, vararg values: V?): T? = ops.evalsha(digest, type, keys, *values).awaitFirstOrNull() + + /** + * Check existence of scripts in the script cache. + * + * @param digests script digests. + * @return List array-reply The command returns an array of integers that correspond to the specified SHA1 + * digest arguments. For every corresponding SHA1 digest of a script that actually exists in the script cache, an 1 + * is returned, otherwise 0 is returned. + * + **/ + override suspend fun scriptExists(vararg digests: String?): List? = ops.scriptExists(*digests).collectList().awaitFirstOrNull() + + /** + * Remove all the scripts from the script cache. + * + * @return String simple-string-reply. + * + **/ + override suspend fun scriptFlush(): String? = ops.scriptFlush().awaitFirstOrNull() + + /** + * Kill the script currently in execution. + * + * @return String simple-string-reply. + * + **/ + override suspend fun scriptKill(): String? = ops.scriptKill().awaitFirstOrNull() + + /** + * Load the specified Lua script into the script cache. + * + * @param script script content. + * @return String bulk-string-reply This command returns the SHA1 digest of the script added into the script cache. + * @since 6.0 + * + **/ + override suspend fun scriptLoad(script: String?): String? = ops.scriptLoad(script).awaitFirstOrNull() + + /** + * Load the specified Lua script into the script cache. + * + * @param script script content. + * @return String bulk-string-reply This command returns the SHA1 digest of the script added into the script cache. + * @since 6.0 + * + **/ + override suspend fun scriptLoad(script: ByteArray?): String? = ops.scriptLoad(script).awaitFirstOrNull() + + /** + * Create a SHA1 digest from a Lua script. + * + * @param script script content. + * @return the SHA1 value. + * @since 6.0 + * + **/ + override suspend fun digest(script: String?): String? = ops.digest(script) + + /** + * Create a SHA1 digest from a Lua script. + * + * @param script script content. + * @return the SHA1 value. + * @since 6.0 + * + **/ + override suspend fun digest(script: ByteArray?): String? = ops.digest(script) + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisServerSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisServerSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..aa761c4802 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisServerSuspendableReactiveCommands.kt @@ -0,0 +1,460 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import java.util.Date +import io.lettuce.core.KillArgs +import io.lettuce.core.TrackingArgs +import io.lettuce.core.UnblockType +import io.lettuce.core.protocol.CommandType + + +/** + * Coroutine executed commands (based on reactive commands) for Server Control. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisServerSuspendableReactiveCommands(private val ops: RedisServerReactiveCommands) : RedisServerSuspendableCommands { + + /** + * Asynchronously rewrite the append-only file. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun bgrewriteaof(): String? = ops.bgrewriteaof().awaitFirstOrNull() + + /** + * Asynchronously save the dataset to disk. + * + * @return String simple-string-reply. + * + **/ + override suspend fun bgsave(): String? = ops.bgsave().awaitFirstOrNull() + + /** + * Control tracking of keys in the context of server-assisted client cache invalidation. + * + * @param enabled @code true} to enable key tracking. + * @return String simple-string-reply {@code OK}. + * @since 6.0 + * + **/ + override suspend fun clientCaching(enabled: Boolean): String? = ops.clientCaching(enabled).awaitFirstOrNull() + + /** + * Get the current connection name. + * + * @return K bulk-string-reply The connection name, or a null bulk reply if no name is set. + * + **/ + override suspend fun clientGetname(): K? = ops.clientGetname().awaitFirstOrNull() + + /** + * Returns the client ID we are redirecting our tracking notifications to. + * + * @return the ID of the client we are redirecting the notifications to. The command returns -1 if client tracking is not + * enabled, or 0 if client tracking is enabled but we are not redirecting the notifications to any client. + * @since 6.0 + * + **/ + override suspend fun clientGetredir(): Long? = ops.clientGetredir().awaitFirstOrNull() + + /** + * Get the id of the current connection. + * + * @return Long The command just returns the ID of the current connection. + * @since 5.3 + * + **/ + override suspend fun clientId(): Long? = ops.clientId().awaitFirstOrNull() + + /** + * Kill the connection of a client identified by ip:port. + * + * @param addr ip:port. + * @return String simple-string-reply {@code OK} if the connection exists and has been closed. + * + **/ + override suspend fun clientKill(addr: String?): String? = ops.clientKill(addr).awaitFirstOrNull() + + /** + * Kill connections of clients which are filtered by {@code killArgs}. + * + * @param killArgs args for the kill operation. + * @return Long integer-reply number of killed connections. + * + **/ + override suspend fun clientKill(killArgs: KillArgs?): Long? = ops.clientKill(killArgs).awaitFirstOrNull() + + /** + * Get the list of client connections. + * + * @return String bulk-string-reply a unique string, formatted as follows: One client connection per line (separated by LF), + * each line is composed of a succession of property=value fields separated by a space character. + * + **/ + override suspend fun clientList(): String? = ops.clientList().awaitFirstOrNull() + + /** + * Stop processing commands from clients for some time. + * + * @param timeout the timeout value in milliseconds. + * @return String simple-string-reply The command returns OK or an error if the timeout is invalid. + * + **/ + override suspend fun clientPause(timeout: Long): String? = ops.clientPause(timeout).awaitFirstOrNull() + + /** + * Set the current connection name. + * + * @param name the client name. + * @return simple-string-reply {@code OK} if the connection name was successfully set. + * + **/ + override suspend fun clientSetname(name: K?): String? = ops.clientSetname(name).awaitFirstOrNull() + + /** + * Enables the tracking feature of the Redis server, that is used for server assisted client side caching. Tracking messages + * are either available when using the RESP3 protocol or through Pub/Sub notification when using RESP2. + * + * @param args for the CLIENT TRACKING operation. + * @return String simple-string-reply {@code OK}. + * @since 6.0 + * + **/ + override suspend fun clientTracking(args: TrackingArgs?): String? = ops.clientTracking(args).awaitFirstOrNull() + + /** + * Unblock the specified blocked client. + * + * @param id the client id. + * @param type unblock type. + * @return Long integer-reply number of unblocked connections. + * @since 5.1 + * + **/ + override suspend fun clientUnblock(id: Long, type: UnblockType?): Long? = ops.clientUnblock(id, type).awaitFirstOrNull() + + /** + * Returns an array reply of details about all Redis commands. + * + * @return List array-reply. + * + **/ + override suspend fun command(): List? = ops.command().collectList().awaitFirstOrNull() + + /** + * Get total number of Redis commands. + * + * @return Long integer-reply of number of total commands in this Redis server. + * + **/ + override suspend fun commandCount(): Long? = ops.commandCount().awaitFirstOrNull() + + /** + * Returns an array reply of details about the requested commands. + * + * @param commands the commands to query for. + * @return List array-reply. + * + **/ + override suspend fun commandInfo(vararg commands: String?): List? = ops.commandInfo(*commands).collectList().awaitFirstOrNull() + + /** + * Returns an array reply of details about the requested commands. + * + * @param commands the commands to query for. + * @return List array-reply. + * + **/ + override suspend fun commandInfo(vararg commands: CommandType?): List? = ops.commandInfo(*commands).collectList().awaitFirstOrNull() + + /** + * Get the value of a configuration parameter. + * + * @param parameter name of the parameter. + * @return Map bulk-string-reply. + * + **/ + override suspend fun configGet(parameter: String?): Map? = ops.configGet(parameter).awaitFirstOrNull() + + /** + * Reset the stats returned by INFO. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun configResetstat(): String? = ops.configResetstat().awaitFirstOrNull() + + /** + * Rewrite the configuration file with the in memory configuration. + * + * @return String simple-string-reply {@code OK} when the configuration was rewritten properly. Otherwise an error is + * returned. + * + **/ + override suspend fun configRewrite(): String? = ops.configRewrite().awaitFirstOrNull() + + /** + * Set a configuration parameter to the given value. + * + * @param parameter the parameter name. + * @param value the parameter value. + * @return String simple-string-reply: {@code OK} when the configuration was set properly. Otherwise an error is returned. + * + **/ + override suspend fun configSet(parameter: String?, value: String?): String? = ops.configSet(parameter, value).awaitFirstOrNull() + + /** + * Return the number of keys in the selected database. + * + * @return Long integer-reply. + * + **/ + override suspend fun dbsize(): Long? = ops.dbsize().awaitFirstOrNull() + + /** + * Crash and recover. + * + * @param delay optional delay in milliseconds. + * @return String simple-string-reply. + * + **/ + override suspend fun debugCrashAndRecover(delay: Long?): String? = ops.debugCrashAndRecover(delay).awaitFirstOrNull() + + /** + * Get debugging information about the internal hash-table state. + * + * @param db the database number. + * @return String simple-string-reply. + * + **/ + override suspend fun debugHtstats(db: Int): String? = ops.debugHtstats(db).awaitFirstOrNull() + + /** + * Get debugging information about a key. + * + * @param key the key. + * @return String simple-string-reply. + * + **/ + override suspend fun debugObject(key: K?): String? = ops.debugObject(key).awaitFirstOrNull() + + /** + * Make the server crash: Out of memory. + * + * @return nothing, because the server crashes before returning. + * + **/ + override suspend fun debugOom(): Unit? = ops.debugOom().awaitFirstOrNull().let { Unit } + + /** + * Save RDB, clear the database and reload RDB. + * + * @return String simple-string-reply The commands returns OK on success. + * + **/ + override suspend fun debugReload(): String? = ops.debugReload().awaitFirstOrNull() + + /** + * Restart the server gracefully. + * + * @param delay optional delay in milliseconds. + * @return String simple-string-reply. + * + **/ + override suspend fun debugRestart(delay: Long?): String? = ops.debugRestart(delay).awaitFirstOrNull() + + /** + * Get debugging information about the internal SDS length. + * + * @param key the key. + * @return String simple-string-reply. + * + **/ + override suspend fun debugSdslen(key: K?): String? = ops.debugSdslen(key).awaitFirstOrNull() + + /** + * Make the server crash: Invalid pointer access. + * + * @return nothing, because the server crashes before returning. + * + **/ + override suspend fun debugSegfault(): Unit? = ops.debugSegfault().awaitFirstOrNull().let { Unit } + + /** + * Remove all keys from all databases. + * + * @return String simple-string-reply. + * + **/ + override suspend fun flushall(): String? = ops.flushall().awaitFirstOrNull() + + /** + * Remove all keys asynchronously from all databases. + * + * @return String simple-string-reply. + * + **/ + override suspend fun flushallAsync(): String? = ops.flushallAsync().awaitFirstOrNull() + + /** + * Remove all keys from the current database. + * + * @return String simple-string-reply. + * + **/ + override suspend fun flushdb(): String? = ops.flushdb().awaitFirstOrNull() + + /** + * Remove all keys asynchronously from the current database. + * + * @return String simple-string-reply. + * + **/ + override suspend fun flushdbAsync(): String? = ops.flushdbAsync().awaitFirstOrNull() + + /** + * Get information and statistics about the server. + * + * @return String bulk-string-reply as a collection of text lines. + * + **/ + override suspend fun info(): String? = ops.info().awaitFirstOrNull() + + /** + * Get information and statistics about the server. + * + * @param section the section type: string. + * @return String bulk-string-reply as a collection of text lines. + * + **/ + override suspend fun info(section: String?): String? = ops.info(section).awaitFirstOrNull() + + /** + * Get the UNIX time stamp of the last successful save to disk. + * + * @return Date integer-reply an UNIX time stamp. + * + **/ + override suspend fun lastsave(): Date? = ops.lastsave().awaitFirstOrNull() + + /** + * Reports the number of bytes that a key and its value require to be stored in RAM. + * + * @return memory usage in bytes. + * @since 5.2 + * + **/ + override suspend fun memoryUsage(key: K?): Long? = ops.memoryUsage(key).awaitFirstOrNull() + + /** + * Synchronously save the dataset to disk. + * + * @return String simple-string-reply The commands returns OK on success. + * + **/ + override suspend fun save(): String? = ops.save().awaitFirstOrNull() + + /** + * Synchronously save the dataset to disk and then shut down the server. + * + * @param save @code true} force save operation. + * + **/ + override suspend fun shutdown(save: Boolean): Unit? = ops.shutdown(save).awaitFirstOrNull().let { Unit } + + /** + * Make the server a replica of another instance, or promote it as master. + * + * @param host the host type: string. + * @param port the port type: string. + * @return String simple-string-reply. + * + **/ + override suspend fun slaveof(host: String?, port: Int): String? = ops.slaveof(host, port).awaitFirstOrNull() + + /** + * Promote server as master. + * + * @return String simple-string-reply. + * + **/ + override suspend fun slaveofNoOne(): String? = ops.slaveofNoOne().awaitFirstOrNull() + + /** + * Read the slow log. + * + * @return List deeply nested multi bulk replies. + * + **/ + override suspend fun slowlogGet(): List? = ops.slowlogGet().collectList().awaitFirstOrNull() + + /** + * Read the slow log. + * + * @param count the count. + * @return List deeply nested multi bulk replies. + * + **/ + override suspend fun slowlogGet(count: Int): List? = ops.slowlogGet(count).collectList().awaitFirstOrNull() + + /** + * Obtaining the current length of the slow log. + * + * @return Long length of the slow log. + * + **/ + override suspend fun slowlogLen(): Long? = ops.slowlogLen().awaitFirstOrNull() + + /** + * Resetting the slow log. + * + * @return String simple-string-reply The commands returns OK on success. + * + **/ + override suspend fun slowlogReset(): String? = ops.slowlogReset().awaitFirstOrNull() + + /** + * Return the current server time. + * + * @return List array-reply specifically: + * + * A multi bulk reply containing two elements: + * + * unix time in seconds. microseconds. + * + **/ + override suspend fun time(): List? = ops.time().collectList().awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisSetSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisSetSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..28297bb590 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisSetSuspendableReactiveCommands.kt @@ -0,0 +1,347 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.ScanArgs +import io.lettuce.core.ScanCursor +import io.lettuce.core.StreamScanCursor +import io.lettuce.core.ValueScanCursor +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on reactive commands) for Sets. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisSetSuspendableReactiveCommands(private val ops: RedisSetReactiveCommands) : RedisSetSuspendableCommands { + + /** + * Add one or more members to a set. + * + * @param key the key. + * @param members the member type: value. + * @return Long integer-reply the number of elements that were added to the set, not including all the elements already + * present into the set. + * + **/ + override suspend fun sadd(key: K?, vararg members: V?): Long? = ops.sadd(key, *members).awaitFirstOrNull() + + /** + * Get the number of members in a set. + * + * @param key the key. + * @return Long integer-reply the cardinality (number of elements) of the set, or {@code false} if {@code key} does not + * exist. + * + **/ + override suspend fun scard(key: K?): Long? = ops.scard(key).awaitFirstOrNull() + + /** + * Subtract multiple sets. + * + * @param keys the key. + * @return Set array-reply list with members of the resulting set. + * + **/ + override suspend fun sdiff(vararg keys: K?): Set? = ops.sdiff(*keys).collectList().awaitFirstOrNull()?.toSet() + + /** + * Subtract multiple sets. + * + * @param channel the channel. + * @param keys the keys. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun sdiff(channel: ValueStreamingChannel?, vararg keys: K?): Long? = ops.sdiff(channel, *keys).awaitFirstOrNull() + + /** + * Subtract multiple sets and store the resulting set in a key. + * + * @param destination the destination type: key. + * @param keys the key. + * @return Long integer-reply the number of elements in the resulting set. + * + **/ + override suspend fun sdiffstore(destination: K?, vararg keys: K?): Long? = ops.sdiffstore(destination, *keys).awaitFirstOrNull() + + /** + * Intersect multiple sets. + * + * @param keys the key. + * @return Set array-reply list with members of the resulting set. + * + **/ + override suspend fun sinter(vararg keys: K?): Set? = ops.sinter(*keys).collectList().awaitFirstOrNull()?.toSet() + + /** + * Intersect multiple sets. + * + * @param channel the channel. + * @param keys the keys. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun sinter(channel: ValueStreamingChannel?, vararg keys: K?): Long? = ops.sinter(channel, *keys).awaitFirstOrNull() + + /** + * Intersect multiple sets and store the resulting set in a key. + * + * @param destination the destination type: key. + * @param keys the key. + * @return Long integer-reply the number of elements in the resulting set. + * + **/ + override suspend fun sinterstore(destination: K?, vararg keys: K?): Long? = ops.sinterstore(destination, *keys).awaitFirstOrNull() + + /** + * Determine if a given value is a member of a set. + * + * @param key the key. + * @param member the member type: value. + * @return Boolean integer-reply specifically: + * + * {@code true} if the element is a member of the set. {@code false} if the element is not a member of the set, or + * if {@code key} does not exist. + * + **/ + override suspend fun sismember(key: K?, member: V?): Boolean? = ops.sismember(key, member).awaitFirstOrNull() + + /** + * Move a member from one set to another. + * + * @param source the source key. + * @param destination the destination type: key. + * @param member the member type: value. + * @return Boolean integer-reply specifically: + * + * {@code true} if the element is moved. {@code false} if the element is not a member of {@code source} and no + * operation was performed. + * + **/ + override suspend fun smove(source: K?, destination: K?, member: V?): Boolean? = ops.smove(source, destination, member).awaitFirstOrNull() + + /** + * Get all the members in a set. + * + * @param key the key. + * @return Set array-reply all elements of the set. + * + **/ + override suspend fun smembers(key: K?): Set? = ops.smembers(key).collectList().awaitFirstOrNull()?.toSet() + + /** + * Get all the members in a set. + * + * @param channel the channel. + * @param key the keys. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun smembers(channel: ValueStreamingChannel?, key: K?): Long? = ops.smembers(channel, key).awaitFirstOrNull() + + /** + * Remove and return a random member from a set. + * + * @param key the key. + * @return V bulk-string-reply the removed element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun spop(key: K?): V? = ops.spop(key).awaitFirstOrNull() + + /** + * Remove and return one or multiple random members from a set. + * + * @param key the key. + * @param count number of members to pop. + * @return V bulk-string-reply the removed element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun spop(key: K?, count: Long): Set? = ops.spop(key, count).collectList().awaitFirstOrNull()?.toSet() + + /** + * Get one random member from a set. + * + * @param key the key. + * @return V bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply with the + * randomly selected element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun srandmember(key: K?): V? = ops.srandmember(key).awaitFirstOrNull() + + /** + * Get one or multiple random members from a set. + * + * @param key the key. + * @param count the count type: long. + * @return Set bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply + * with the randomly selected element, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun srandmember(key: K?, count: Long): List? = ops.srandmember(key, count).collectList().awaitFirstOrNull() + + /** + * Get one or multiple random members from a set. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param count the count. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun srandmember(channel: ValueStreamingChannel?, key: K?, count: Long): Long? = ops.srandmember(channel, key, count).awaitFirstOrNull() + + /** + * Remove one or more members from a set. + * + * @param key the key. + * @param members the member type: value. + * @return Long integer-reply the number of members that were removed from the set, not including non existing members. + * + **/ + override suspend fun srem(key: K?, vararg members: V?): Long? = ops.srem(key, *members).awaitFirstOrNull() + + /** + * Add multiple sets. + * + * @param keys the key. + * @return Set array-reply list with members of the resulting set. + * + **/ + override suspend fun sunion(vararg keys: K?): Set? = ops.sunion(*keys).collectList().awaitFirstOrNull()?.toSet() + + /** + * Add multiple sets. + * + * @param channel streaming channel that receives a call for every value. + * @param keys the keys. + * @return Long count of members of the resulting set. + * + **/ + override suspend fun sunion(channel: ValueStreamingChannel?, vararg keys: K?): Long? = ops.sunion(channel, *keys).awaitFirstOrNull() + + /** + * Add multiple sets and store the resulting set in a key. + * + * @param destination the destination type: key. + * @param keys the key. + * @return Long integer-reply the number of elements in the resulting set. + * + **/ + override suspend fun sunionstore(destination: K?, vararg keys: K?): Long? = ops.sunionstore(destination, *keys).awaitFirstOrNull() + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @return ValueScanCursor scan cursor. + * + **/ + override suspend fun sscan(key: K?): ValueScanCursor? = ops.sscan(key).awaitFirstOrNull() + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @param scanArgs scan arguments. + * @return ValueScanCursor scan cursor. + * + **/ + override suspend fun sscan(key: K?, scanArgs: ScanArgs?): ValueScanCursor? = ops.sscan(key, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return ValueScanCursor scan cursor. + * + **/ + override suspend fun sscan(key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): ValueScanCursor? = ops.sscan(key, scanCursor, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate Set elements. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return ValueScanCursor scan cursor. + * + **/ + override suspend fun sscan(key: K?, scanCursor: ScanCursor?): ValueScanCursor? = ops.sscan(key, scanCursor).awaitFirstOrNull() + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun sscan(channel: ValueStreamingChannel?, key: K?): StreamScanCursor? = ops.sscan(channel, key).awaitFirstOrNull() + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun sscan(channel: ValueStreamingChannel?, key: K?, scanArgs: ScanArgs?): StreamScanCursor? = ops.sscan(channel, key, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun sscan(channel: ValueStreamingChannel?, key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? = ops.sscan(channel, key, scanCursor, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate Set elements. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun sscan(channel: ValueStreamingChannel?, key: K?, scanCursor: ScanCursor?): StreamScanCursor? = ops.sscan(channel, key, scanCursor).awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisSortedSetSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisSortedSetSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..6855a6e5c5 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisSortedSetSuspendableReactiveCommands.kt @@ -0,0 +1,1368 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.* +import io.lettuce.core.output.ScoredValueStreamingChannel +import io.lettuce.core.output.ValueStreamingChannel + + +/** + * Coroutine executed commands (based on reactive commands) for Sorted Sets. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisSortedSetSuspendableReactiveCommands(private val ops: RedisSortedSetReactiveCommands) : RedisSortedSetSuspendableCommands { + + /** + * Removes and returns a member with the lowest scores in the sorted set stored at one of the keys. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue> multi-bulk containing the name of the key, the score and the popped + * member. + * @since 5.1 + * + **/ + override suspend fun bzpopmin(timeout: Long, vararg keys: K?): KeyValue>? = ops.bzpopmin(timeout, *keys).awaitFirstOrNull() + + /** + * Removes and returns a member with the highest scores in the sorted set stored at one of the keys. + * + * @param timeout the timeout in seconds. + * @param keys the keys. + * @return KeyValue> multi-bulk containing the name of the key, the score and the popped + * member. + * @since 5.1 + * + **/ + override suspend fun bzpopmax(timeout: Long, vararg keys: K?): KeyValue>? = ops.bzpopmax(timeout, *keys).awaitFirstOrNull() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, score: Double, member: V?): Long? = ops.zadd(key, score, member).awaitFirstOrNull() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param scoresAndValues the scoresAndValue tuples (score,value,score,value,...). + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, vararg scoresAndValues: Any?): Long? = ops.zadd(key, *scoresAndValues).awaitFirstOrNull() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param scoredValues the scored values. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, vararg scoredValues: ScoredValue?): Long? = ops.zadd(key, *scoredValues).awaitFirstOrNull() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param zAddArgs arguments for zadd. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, zAddArgs: ZAddArgs?, score: Double, member: V?): Long? = ops.zadd(key, zAddArgs, score, member).awaitFirstOrNull() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the key. + * @param zAddArgs arguments for zadd. + * @param scoresAndValues the scoresAndValue tuples (score,value,score,value,...). + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, zAddArgs: ZAddArgs?, vararg scoresAndValues: Any?): Long? = ops.zadd(key, zAddArgs, *scoresAndValues).awaitFirstOrNull() + + /** + * Add one or more members to a sorted set, or update its score if it already exists. + * + * @param key the ke. + * @param zAddArgs arguments for zadd. + * @param scoredValues the scored values. + * @return Long integer-reply specifically: + * + * The number of elements added to the sorted sets, not including elements already existing for which the score was + * updated. + * + **/ + override suspend fun zadd(key: K?, zAddArgs: ZAddArgs?, vararg scoredValues: ScoredValue?): Long? = ops.zadd(key, zAddArgs, *scoredValues).awaitFirstOrNull() + + /** + * Add one or more members to a sorted set, or update its score if it already exists applying the {@code INCR} option. ZADD + * acts like ZINCRBY. + * + * @param key the key. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: The total number of elements changed. + * + **/ + override suspend fun zaddincr(key: K?, score: Double, member: V?): Double? = ops.zaddincr(key, score, member).awaitFirstOrNull() + + /** + * Add one or more members to a sorted set, or update its score if it already exists applying the {@code INCR} option. ZADD + * acts like ZINCRBY. + * + * @param key the key. + * @param zAddArgs arguments for zadd. + * @param score the score. + * @param member the member. + * @return Long integer-reply specifically: The total number of elements changed. + * @since 4.3 + * + **/ + override suspend fun zaddincr(key: K?, zAddArgs: ZAddArgs?, score: Double, member: V?): Double? = ops.zaddincr(key, zAddArgs, score, member).awaitFirstOrNull() + + /** + * Get the number of members in a sorted set. + * + * @param key the key. + * @return Long integer-reply the cardinality (number of elements) of the sorted set, or {@code false} if {@code key} does + * not exist. + * + **/ + override suspend fun zcard(key: K?): Long? = ops.zcard(key).awaitFirstOrNull() + + /** + * Count the members in a sorted set with scores within the given values. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements in the specified score range. + * @deprecated Use {@link #zcount(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zcount(key: K?, min: Double, max: Double): Long? = ops.zcount(key, min, max).awaitFirstOrNull() + + /** + * Count the members in a sorted set with scores within the given values. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements in the specified score range. + * @deprecated Use {@link #zcount(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zcount(key: K?, min: String?, max: String?): Long? = ops.zcount(key, min, max).awaitFirstOrNull() + + /** + * Count the members in a sorted set with scores within the given {@link Range}. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zcount(key: K?, range: Range?): Long? = ops.zcount(key, range).awaitFirstOrNull() + + /** + * Increment the score of a member in a sorted set. + * + * @param key the key. + * @param amount the increment type: long. + * @param member the member type: value. + * @return Double bulk-string-reply the new score of {@code member} (a double precision floating point number), represented + * as string. + * + **/ + override suspend fun zincrby(key: K?, amount: Double, member: V?): Double? = ops.zincrby(key, amount, member).awaitFirstOrNull() + + /** + * Intersect multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination the destination. + * @param keys the keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + override suspend fun zinterstore(destination: K?, vararg keys: K?): Long? = ops.zinterstore(destination, *keys).awaitFirstOrNull() + + /** + * Intersect multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination the destination. + * @param storeArgs the storeArgs. + * @param keys the keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + override suspend fun zinterstore(destination: K?, storeArgs: ZStoreArgs?, vararg keys: K?): Long? = ops.zinterstore(destination, storeArgs, *keys).awaitFirstOrNull() + + /** + * Count the number of members in a sorted set between a given lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements in the specified score range. + * @deprecated Use {@link #zlexcount(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zlexcount(key: K?, min: String?, max: String?): Long? = ops.zlexcount(key, min, max).awaitFirstOrNull() + + /** + * Count the number of members in a sorted set between a given lexicographical range. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zlexcount(key: K?, range: Range?): Long? = ops.zlexcount(key, range).awaitFirstOrNull() + + /** + * Removes and returns up to count members with the lowest scores in the sorted set stored at key. + * + * @param key the key. + * @return ScoredValue the removed element. + * @since 5.1 + * + **/ + override suspend fun zpopmin(key: K?): ScoredValue? = ops.zpopmin(key).awaitFirstOrNull() + + /** + * Removes and returns up to count members with the lowest scores in the sorted set stored at key. + * + * @param key the key. + * @param count the number of elements to return. + * @return List> array-reply list of popped scores and elements. + * @since 5.1 + * + **/ + override suspend fun zpopmin(key: K?, count: Long): List>? = ops.zpopmin(key, count).collectList().awaitFirstOrNull() + + /** + * Removes and returns up to count members with the highest scores in the sorted set stored at key. + * + * @param key the key. + * @return ScoredValue the removed element. + * @since 5.1 + * + **/ + override suspend fun zpopmax(key: K?): ScoredValue? = ops.zpopmax(key).awaitFirstOrNull() + + /** + * Removes and returns up to count members with the highest scores in the sorted set stored at key. + * + * @param key the key. + * @param count the number of elements to return. + * @return List> array-reply list of popped scores and elements. + * @since 5.1 + * + **/ + override suspend fun zpopmax(key: K?, count: Long): List>? = ops.zpopmax(key, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by index. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun zrange(key: K?, start: Long, stop: Long): List? = ops.zrange(key, start, stop).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by index. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrange(channel: ValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.zrange(channel, key, start, stop).awaitFirstOrNull() + + /** + * Return a range of members with scores in a sorted set, by index. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun zrangeWithScores(key: K?, start: Long, stop: Long): List>? = ops.zrangeWithScores(key, start, stop).collectList().awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by index. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrangeWithScores(channel: ScoredValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.zrangeWithScores(channel, key, start, stop).awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified range. + * @deprecated Use {@link #zrangebylex(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebylex(key: K?, min: String?, max: String?): List? = ops.zrangebylex(key, min, max).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrangebylex(key: K?, range: Range?): List? = ops.zrangebylex(key, range).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified range. + * @deprecated Use {@link #zrangebylex(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebylex(key: K?, min: String?, max: String?, offset: Long, count: Long): List? = ops.zrangebylex(key, min, max, offset, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by lexicographical range. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrangebylex(key: K?, range: Range?, limit: Limit?): List? = ops.zrangebylex(key, range, limit).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(key: K?, min: Double, max: Double): List? = ops.zrangebyscore(key, min, max).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(key: K?, min: String?, max: String?): List? = ops.zrangebyscore(key, min, max).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscore(key: K?, range: Range?): List? = ops.zrangebyscore(key, range).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(key: K?, min: Double, max: Double, offset: Long, count: Long): List? = ops.zrangebyscore(key, min, max, offset, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(key: K?, min: String?, max: String?, offset: Long, count: Long): List? = ops.zrangebyscore(key, min, max, offset, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscore(key: K?, range: Range?, limit: Limit?): List? = ops.zrangebyscore(key, range, limit).collectList().awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: Double, max: Double): Long? = ops.zrangebyscore(channel, key, min, max).awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: String?, max: String?): Long? = ops.zrangebyscore(channel, key, min, max).awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?): Long? = ops.zrangebyscore(channel, key, range).awaitFirstOrNull() + + /** + * Stream over range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: Double, max: Double, offset: Long, count: Long): Long? = ops.zrangebyscore(channel, key, min, max, offset, count).awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscore(ValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, min: String?, max: String?, offset: Long, count: Long): Long? = ops.zrangebyscore(channel, key, min, max, offset, count).awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? = ops.zrangebyscore(channel, key, range, limit).awaitFirstOrNull() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(key: K?, min: Double, max: Double): List>? = ops.zrangebyscoreWithScores(key, min, max).collectList().awaitFirstOrNull() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(key: K?, min: String?, max: String?): List>? = ops.zrangebyscoreWithScores(key, min, max).collectList().awaitFirstOrNull() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @return List> array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscoreWithScores(key: K?, range: Range?): List>? = ops.zrangebyscoreWithScores(key, range).collectList().awaitFirstOrNull() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(key: K?, min: Double, max: Double, offset: Long, count: Long): List>? = ops.zrangebyscoreWithScores(key, min, max, offset, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(key: K?, min: String?, max: String?, offset: Long, count: Long): List>? = ops.zrangebyscoreWithScores(key, min, max, offset, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members with score in a sorted set, by score. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List> array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscoreWithScores(key: K?, range: Range?, limit: Limit?): List>? = ops.zrangebyscoreWithScores(key, range, limit).collectList().awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: Double, max: Double): Long? = ops.zrangebyscoreWithScores(channel, key, min, max).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: String?, max: String?): Long? = ops.zrangebyscoreWithScores(channel, key, min, max).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?): Long? = ops.zrangebyscoreWithScores(channel, key, range).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: Double, max: Double, offset: Long, count: Long): Long? = ops.zrangebyscoreWithScores(channel, key, min, max, offset, count).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified score range. + * @deprecated Use {@link #zrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, min: String?, max: String?, offset: Long, count: Long): Long? = ops.zrangebyscoreWithScores(channel, key, min, max, offset, count).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? = ops.zrangebyscoreWithScores(channel, key, range, limit).awaitFirstOrNull() + + /** + * Determine the index of a member in a sorted set. + * + * @param key the key. + * @param member the member type: value. + * @return Long integer-reply the rank of {@code member}. If {@code member} does not exist in the sorted set or {@code key} + * does not exist,. + * + **/ + override suspend fun zrank(key: K?, member: V?): Long? = ops.zrank(key, member).awaitFirstOrNull() + + /** + * Remove one or more members from a sorted set. + * + * @param key the key. + * @param members the member type: value. + * @return Long integer-reply specifically: + * + * The number of members removed from the sorted set, not including non existing members. + * + **/ + override suspend fun zrem(key: K?, vararg members: V?): Long? = ops.zrem(key, *members).awaitFirstOrNull() + + /** + * Remove all members in a sorted set between the given lexicographical range. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements removed. + * @deprecated Use {@link #zremrangebylex(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zremrangebylex(key: K?, min: String?, max: String?): Long? = ops.zremrangebylex(key, min, max).awaitFirstOrNull() + + /** + * Remove all members in a sorted set between the given lexicographical range. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements removed. + * @since 4.3 + * + **/ + override suspend fun zremrangebylex(key: K?, range: Range?): Long? = ops.zremrangebylex(key, range).awaitFirstOrNull() + + /** + * Remove all members in a sorted set within the given indexes. + * + * @param key the key. + * @param start the start type: long. + * @param stop the stop type: long. + * @return Long integer-reply the number of elements removed. + * + **/ + override suspend fun zremrangebyrank(key: K?, start: Long, stop: Long): Long? = ops.zremrangebyrank(key, start, stop).awaitFirstOrNull() + + /** + * Remove all members in a sorted set within the given scores. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements removed. + * @deprecated Use {@link #zremrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zremrangebyscore(key: K?, min: Double, max: Double): Long? = ops.zremrangebyscore(key, min, max).awaitFirstOrNull() + + /** + * Remove all members in a sorted set within the given scores. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long integer-reply the number of elements removed. + * @deprecated Use {@link #zremrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zremrangebyscore(key: K?, min: String?, max: String?): Long? = ops.zremrangebyscore(key, min, max).awaitFirstOrNull() + + /** + * Remove all members in a sorted set within the given scores. + * + * @param key the key. + * @param range the range. + * @return Long integer-reply the number of elements removed. + * @since 4.3 + * + **/ + override suspend fun zremrangebyscore(key: K?, range: Range?): Long? = ops.zremrangebyscore(key, range).awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by index, with scores ordered from high to low. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun zrevrange(key: K?, start: Long, stop: Long): List? = ops.zrevrange(key, start, stop).collectList().awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by index, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrevrange(channel: ValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.zrevrange(channel, key, start, stop).awaitFirstOrNull() + + /** + * Return a range of members with scores in a sorted set, by index, with scores ordered from high to low. + * + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return List array-reply list of elements in the specified range. + * + **/ + override suspend fun zrevrangeWithScores(key: K?, start: Long, stop: Long): List>? = ops.zrevrangeWithScores(key, start, stop).collectList().awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by index, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param start the start. + * @param stop the stop. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrevrangeWithScores(channel: ScoredValueStreamingChannel?, key: K?, start: Long, stop: Long): Long? = ops.zrevrangeWithScores(channel, key, start, stop).awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by lexicographical range ordered from high to low. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebylex(key: K?, range: Range?): List? = ops.zrevrangebylex(key, range).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by lexicographical range ordered from high to low. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebylex(key: K?, range: Range?, limit: Limit?): List? = ops.zrevrangebylex(key, range, limit).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(key: K?, max: Double, min: Double): List? = ops.zrevrangebyscore(key, max, min).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param min min score. + * @param max max score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(key: K?, max: String?, min: String?): List? = ops.zrevrangebyscore(key, max, min).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscore(key: K?, range: Range?): List? = ops.zrevrangebyscore(key, range).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the withscores. + * @param count the null. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(key: K?, max: Double, min: Double, offset: Long, count: Long): List? = ops.zrevrangebyscore(key, max, min, offset, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(key: K?, max: String?, min: String?, offset: Long, count: Long): List? = ops.zrevrangebyscore(key, max, min, offset, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscore(key: K?, range: Range?, limit: Limit?): List? = ops.zrevrangebyscore(key, range, limit).collectList().awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param max max score. + * @param min min score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: Double, min: Double): Long? = ops.zrevrangebyscore(channel, key, max, min).awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscore(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: String?, min: String?): Long? = ops.zrevrangebyscore(channel, key, max, min).awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?): Long? = ops.zrevrangebyscore(channel, key, range).awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: Double, min: Double, offset: Long, count: Long): Long? = ops.zrevrangebyscore(channel, key, max, min, offset, count).awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, max: String?, min: String?, offset: Long, count: Long): Long? = ops.zrevrangebyscore(channel, key, max, min, offset, count).awaitFirstOrNull() + + /** + * Stream over a range of members in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscore(channel: ValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? = ops.zrevrangebyscore(channel, key, range, limit).awaitFirstOrNull() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(key: K?, max: Double, min: Double): List>? = ops.zrevrangebyscoreWithScores(key, max, min).collectList().awaitFirstOrNull() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(key: K?, max: String?, min: String?): List>? = ops.zrevrangebyscoreWithScores(key, max, min).collectList().awaitFirstOrNull() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @return List> array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscoreWithScores(key: K?, range: Range?): List>? = ops.zrevrangebyscoreWithScores(key, range).collectList().awaitFirstOrNull() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the offset. + * @param count the count. + * @return List> array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(key: K?, max: Double, min: Double, offset: Long, count: Long): List>? = ops.zrevrangebyscoreWithScores(key, max, min, offset, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param max max score. + * @param min min score. + * @param offset the offset. + * @param count the count. + * @return List array-reply list of elements in the specified score range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(key: K?, max: String?, min: String?, offset: Long, count: Long): List>? = ops.zrevrangebyscoreWithScores(key, max, min, offset, count).collectList().awaitFirstOrNull() + + /** + * Return a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param key the key. + * @param range the range. + * @param limit limit. + * @return List array-reply list of elements in the specified score range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscoreWithScores(key: K?, range: Range?, limit: Limit?): List>? = ops.zrevrangebyscoreWithScores(key, range, limit).collectList().awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: Double, min: Double): Long? = ops.zrevrangebyscoreWithScores(channel, key, max, min).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: String?, min: String?): Long? = ops.zrevrangebyscoreWithScores(channel, key, max, min).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @return Long count of elements in the specified range. + * + **/ + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?): Long? = ops.zrevrangebyscoreWithScores(channel, key, range).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: Double, min: Double, offset: Long, count: Long): Long? = ops.zrevrangebyscoreWithScores(channel, key, max, min, offset, count).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param min min score. + * @param max max score. + * @param offset the offset. + * @param count the count. + * @return Long count of elements in the specified range. + * @deprecated Use {@link #zrevrangebyscoreWithScores(ScoredValueStreamingChannel, java.lang.Object, Range, Limit)}. + * + **/ + @Deprecated(message = "Use another API instead.") + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, max: String?, min: String?, offset: Long, count: Long): Long? = ops.zrevrangebyscoreWithScores(channel, key, max, min, offset, count).awaitFirstOrNull() + + /** + * Stream over a range of members with scores in a sorted set, by score, with scores ordered from high to low. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param range the range. + * @param limit the limit. + * @return Long count of elements in the specified range. + * @since 4.3 + * + **/ + override suspend fun zrevrangebyscoreWithScores(channel: ScoredValueStreamingChannel?, key: K?, range: Range?, limit: Limit?): Long? = ops.zrevrangebyscoreWithScores(channel, key, range, limit).awaitFirstOrNull() + + /** + * Determine the index of a member in a sorted set, with scores ordered from high to low. + * + * @param key the key. + * @param member the member type: value. + * @return Long integer-reply the rank of {@code member}. If {@code member} does not exist in the sorted set or {@code key} + * does not exist,. + * + **/ + override suspend fun zrevrank(key: K?, member: V?): Long? = ops.zrevrank(key, member).awaitFirstOrNull() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @return ScoredValueScanCursor scan cursor. + * + **/ + override suspend fun zscan(key: K?): ScoredValueScanCursor? = ops.zscan(key).awaitFirstOrNull() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @param scanArgs scan arguments. + * @return ScoredValueScanCursor scan cursor. + * + **/ + override suspend fun zscan(key: K?, scanArgs: ScanArgs?): ScoredValueScanCursor? = ops.zscan(key, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return ScoredValueScanCursor scan cursor. + * + **/ + override suspend fun zscan(key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): ScoredValueScanCursor? = ops.zscan(key, scanCursor, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return ScoredValueScanCursor scan cursor. + * + **/ + override suspend fun zscan(key: K?, scanCursor: ScanCursor?): ScoredValueScanCursor? = ops.zscan(key, scanCursor).awaitFirstOrNull() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?): StreamScanCursor? = ops.zscan(channel, key).awaitFirstOrNull() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?, scanArgs: ScanArgs?): StreamScanCursor? = ops.zscan(channel, key, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @param scanArgs scan arguments. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?, scanCursor: ScanCursor?, scanArgs: ScanArgs?): StreamScanCursor? = ops.zscan(channel, key, scanCursor, scanArgs).awaitFirstOrNull() + + /** + * Incrementally iterate sorted sets elements and associated scores. + * + * @param channel streaming channel that receives a call for every scored value. + * @param key the key. + * @param scanCursor cursor to resume from a previous scan, must not be {@code null}. + * @return StreamScanCursor scan cursor. + * + **/ + override suspend fun zscan(channel: ScoredValueStreamingChannel?, key: K?, scanCursor: ScanCursor?): StreamScanCursor? = ops.zscan(channel, key, scanCursor).awaitFirstOrNull() + + /** + * Get the score associated with the given member in a sorted set. + * + * @param key the key. + * @param member the member type: value. + * @return Double bulk-string-reply the score of {@code member} (a double precision floating point number), represented as + * string. + * + **/ + override suspend fun zscore(key: K?, member: V?): Double? = ops.zscore(key, member).awaitFirstOrNull() + + /** + * Add multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination destination key. + * @param keys source keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + override suspend fun zunionstore(destination: K?, vararg keys: K?): Long? = ops.zunionstore(destination, *keys).awaitFirstOrNull() + + /** + * Add multiple sorted sets and store the resulting sorted set in a new key. + * + * @param destination the destination. + * @param storeArgs the storeArgs. + * @param keys the keys. + * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. + * + **/ + override suspend fun zunionstore(destination: K?, storeArgs: ZStoreArgs?, vararg keys: K?): Long? = ops.zunionstore(destination, storeArgs, *keys).awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisStreamSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisStreamSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..6da2c8e563 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisStreamSuspendableReactiveCommands.kt @@ -0,0 +1,374 @@ +/* + * Copyright 2018-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.Consumer +import io.lettuce.core.Limit +import io.lettuce.core.Range +import io.lettuce.core.StreamMessage +import io.lettuce.core.XAddArgs +import io.lettuce.core.XGroupCreateArgs +import io.lettuce.core.XReadArgs +import io.lettuce.core.XClaimArgs +import io.lettuce.core.XReadArgs.StreamOffset +import io.lettuce.core.models.stream.PendingMessage +import io.lettuce.core.models.stream.PendingMessages + + +/** + * Coroutine executed commands (based on reactive commands) for Streams. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 5.1 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisStreamSuspendableReactiveCommands(private val ops: RedisStreamReactiveCommands) : RedisStreamSuspendableCommands { + + /** + * Acknowledge one or more messages as processed. + * + * @param key the stream key. + * @param group name of the consumer group. + * @param messageIds message Id's to acknowledge. + * @return simple-reply the lenght of acknowledged messages. + * + **/ + override suspend fun xack(key: K?, group: K?, vararg messageIds: String?): Long? = ops.xack(key, group, *messageIds).awaitFirstOrNull() + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param body message body. + * @return simple-reply the message Id. + * + **/ + override suspend fun xadd(key: K?, body: Map?): String? = ops.xadd(key, body).awaitFirstOrNull() + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param args + * @param body message body. + * @return simple-reply the message Id. + * + **/ + override suspend fun xadd(key: K?, args: XAddArgs?, body: Map?): String? = ops.xadd(key, args, body).awaitFirstOrNull() + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param keysAndValues message body. + * @return simple-reply the message Id. + * + **/ + override suspend fun xadd(key: K?, vararg keysAndValues: Any?): String? = ops.xadd(key, *keysAndValues).awaitFirstOrNull() + + /** + * Append a message to the stream {@code key}. + * + * @param key the stream key. + * @param args + * @param keysAndValues message body. + * @return simple-reply the message Id. + * + **/ + override suspend fun xadd(key: K?, args: XAddArgs?, vararg keysAndValues: Any?): String? = ops.xadd(key, args, *keysAndValues).awaitFirstOrNull() + + /** + * Gets ownership of one or multiple messages in the Pending Entries List of a given stream consumer group. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @param minIdleTime + * @param messageIds message Id's to claim. + * @return simple-reply the {@link StreamMessage}. + * + **/ + override suspend fun xclaim(key: K?, consumer: Consumer?, minIdleTime: Long, vararg messageIds: String?): List>? = ops.xclaim(key, consumer, minIdleTime, *messageIds).collectList().awaitFirstOrNull() + + /** + * Gets ownership of one or multiple messages in the Pending Entries List of a given stream consumer group. + *

+ * Note that setting the {@code JUSTID} flag (calling this method with {@link XClaimArgs#justid()}) suppresses the message + * bode and {@link StreamMessage#getBody()} is {@code null}. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @param args + * @param messageIds message Id's to claim. + * @return simple-reply the {@link StreamMessage}. + * + **/ + override suspend fun xclaim(key: K?, consumer: Consumer?, args: XClaimArgs?, vararg messageIds: String?): List>? = ops.xclaim(key, consumer, args, *messageIds).collectList().awaitFirstOrNull() + + /** + * Removes the specified entries from the stream. Returns the number of items deleted, that may be different from the number + * of IDs passed in case certain IDs do not exist. + * + * @param key the stream key. + * @param messageIds stream message Id's. + * @return simple-reply number of removed entries. + * + **/ + override suspend fun xdel(key: K?, vararg messageIds: String?): Long? = ops.xdel(key, *messageIds).awaitFirstOrNull() + + /** + * Create a consumer group. + * + * @param streamOffset name of the stream containing the offset to set. + * @param group name of the consumer group. + * @return simple-reply {@code true} if successful. + * + **/ + override suspend fun xgroupCreate(streamOffset: StreamOffset?, group: K?): String? = ops.xgroupCreate(streamOffset, group).awaitFirstOrNull() + + /** + * Create a consumer group. + * + * @param streamOffset name of the stream containing the offset to set. + * @param group name of the consumer group. + * @param args + * @return simple-reply {@code true} if successful. + * @since 5.2 + * + **/ + override suspend fun xgroupCreate(streamOffset: StreamOffset?, group: K?, args: XGroupCreateArgs?): String? = ops.xgroupCreate(streamOffset, group, args).awaitFirstOrNull() + + /** + * Delete a consumer from a consumer group. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @return Long integer-reply number of pending messages. + * + **/ + override suspend fun xgroupDelconsumer(key: K?, consumer: Consumer?): Long? = ops.xgroupDelconsumer(key, consumer).awaitFirstOrNull() + + /** + * Destroy a consumer group. + * + * @param key the stream key. + * @param group name of the consumer group. + * @return simple-reply {@code true} if successful. + * + **/ + override suspend fun xgroupDestroy(key: K?, group: K?): Boolean? = ops.xgroupDestroy(key, group).awaitFirstOrNull() + + /** + * Set the current {@code group} id. + * + * @param streamOffset name of the stream containing the offset to set. + * @param group name of the consumer group. + * @return simple-reply OK. + * + **/ + override suspend fun xgroupSetid(streamOffset: StreamOffset?, group: K?): String? = ops.xgroupSetid(streamOffset, group).awaitFirstOrNull() + + /** + * Retrieve information about the stream at {@code key}. + * + * @param key the stream key. + * @return List array-reply. + * @since 5.2 + * + **/ + override suspend fun xinfoStream(key: K?): List? = ops.xinfoStream(key).collectList().awaitFirstOrNull() + + /** + * Retrieve information about the stream consumer groups at {@code key}. + * + * @param key the stream key. + * @return List array-reply. + * @since 5.2 + * + **/ + override suspend fun xinfoGroups(key: K?): List? = ops.xinfoGroups(key).collectList().awaitFirstOrNull() + + /** + * Retrieve information about consumer groups of group {@code group} and stream at {@code key}. + * + * @param key the stream key. + * @param group name of the consumer group. + * @return List array-reply. + * @since 5.2 + * + **/ + override suspend fun xinfoConsumers(key: K?, group: K?): List? = ops.xinfoConsumers(key, group).collectList().awaitFirstOrNull() + + /** + * Get the length of a steam. + * + * @param key the stream key. + * @return simple-reply the lenght of the stream. + * + **/ + override suspend fun xlen(key: K?): Long? = ops.xlen(key).awaitFirstOrNull() + + /** + * Read pending messages from a stream for a {@code group}. + * + * @param key the stream key. + * @param group name of the consumer group. + * @return List array-reply list pending entries. + * + **/ + override suspend fun xpending(key: K?, group: K?): PendingMessages? = ops.xpending(key, group).awaitFirstOrNull() + + /** + * Read pending messages from a stream within a specific {@link Range}. + * + * @param key the stream key. + * @param group name of the consumer group. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xpending(key: K?, group: K?, range: Range?, limit: Limit?): List? = ops.xpending(key, group, range, limit).collectList().awaitFirstOrNull() + + /** + * Read pending messages from a stream within a specific {@link Range}. + * + * @param key the stream key. + * @param consumer consumer identified by group name and consumer key. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xpending(key: K?, consumer: Consumer?, range: Range?, limit: Limit?): List? = ops.xpending(key, consumer, range, limit).collectList().awaitFirstOrNull() + + /** + * Read messages from a stream within a specific {@link Range}. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xrange(key: K?, range: Range?): List>? = ops.xrange(key, range).collectList().awaitFirstOrNull() + + /** + * Read messages from a stream within a specific {@link Range} applying a {@link Limit}. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xrange(key: K?, range: Range?, limit: Limit?): List>? = ops.xrange(key, range, limit).collectList().awaitFirstOrNull() + + /** + * Read messages from one or more {@link StreamOffset}s. + * + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xread(vararg streams: StreamOffset?): List>? = ops.xread(*streams).collectList().awaitFirstOrNull() + + /** + * Read messages from one or more {@link StreamOffset}s. + * + * @param args read arguments. + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xread(args: XReadArgs?, vararg streams: StreamOffset?): List>? = ops.xread(args, *streams).collectList().awaitFirstOrNull() + + /** + * Read messages from one or more {@link StreamOffset}s using a consumer group. + * + * @param consumer consumer/group. + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xreadgroup(consumer: Consumer?, vararg streams: StreamOffset?): List>? = ops.xreadgroup(consumer, *streams).collectList().awaitFirstOrNull() + + /** + * Read messages from one or more {@link StreamOffset}s using a consumer group. + * + * @param consumer consumer/group. + * @param args read arguments. + * @param streams the streams to read from. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xreadgroup(consumer: Consumer?, args: XReadArgs?, vararg streams: StreamOffset?): List>? = ops.xreadgroup(consumer, args, *streams).collectList().awaitFirstOrNull() + + /** + * Read messages from a stream within a specific {@link Range} in reverse order. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xrevrange(key: K?, range: Range?): List>? = ops.xrevrange(key, range).collectList().awaitFirstOrNull() + + /** + * Read messages from a stream within a specific {@link Range} applying a {@link Limit} in reverse order. + * + * @param key the stream key. + * @param range must not be {@code null}. + * @param limit must not be {@code null}. + * @return List array-reply list with members of the resulting stream. + * + **/ + override suspend fun xrevrange(key: K?, range: Range?, limit: Limit?): List>? = ops.xrevrange(key, range, limit).collectList().awaitFirstOrNull() + + /** + * Trims the stream to {@code count} elements. + * + * @param key the stream key. + * @param count length of the stream. + * @return simple-reply number of removed entries. + * + **/ + override suspend fun xtrim(key: K?, count: Long): Long? = ops.xtrim(key, count).awaitFirstOrNull() + + /** + * Trims the stream to {@code count} elements. + * + * @param key the stream key. + * @param approximateTrimming @code true} to trim approximately using the {@code ~} flag. + * @param count length of the stream. + * @return simple-reply number of removed entries. + * + **/ + override suspend fun xtrim(key: K?, approximateTrimming: Boolean, count: Long): Long? = ops.xtrim(key, approximateTrimming, count).awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisStringSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisStringSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..e7e319fbc9 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisStringSuspendableReactiveCommands.kt @@ -0,0 +1,434 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.BitFieldArgs +import io.lettuce.core.KeyValue +import io.lettuce.core.SetArgs +import io.lettuce.core.StrAlgoArgs +import io.lettuce.core.StringMatchResult +import io.lettuce.core.output.KeyValueStreamingChannel + + +/** + * Coroutine executed commands (based on reactive commands) for Strings. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisStringSuspendableReactiveCommands(private val ops: RedisStringReactiveCommands) : RedisStringSuspendableCommands { + + /** + * Append a value to a key. + * + * @param key the key. + * @param value the value. + * @return Long integer-reply the length of the string after the append operation. + * + **/ + override suspend fun append(key: K?, value: V?): Long? = ops.append(key, value).awaitFirstOrNull() + + /** + * Count set bits in a string. + * + * @param key the key. + * @return Long integer-reply The number of bits set to 1. + * + **/ + override suspend fun bitcount(key: K?): Long? = ops.bitcount(key).awaitFirstOrNull() + + /** + * Count set bits in a string. + * + * @param key the key. + * @param start the start. + * @param end the end. + * @return Long integer-reply The number of bits set to 1. + * + **/ + override suspend fun bitcount(key: K?, start: Long, end: Long): Long? = ops.bitcount(key, start, end).awaitFirstOrNull() + + /** + * Execute {@code BITFIELD} with its subcommands. + * + * @param key the key. + * @param bitFieldArgs the args containing subcommands, must not be {@code null}. + * @return Long bulk-reply the results from the bitfield commands. + * + **/ + override suspend fun bitfield(key: K?, bitFieldArgs: BitFieldArgs?): List? = ops.bitfield(key, bitFieldArgs).map { it.value }.collectList().awaitFirstOrNull() + + /** + * Find first bit set or clear in a string. + * + * @param key the key. + * @param state the state. + * @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request. + * + * If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is + * returned. + * + * If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns + * the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the + * command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1. + * + * Basically the function consider the right of the string as padded with zeros if you look for clear bits and + * specify no range or the start argument only. + * + **/ + override suspend fun bitpos(key: K?, state: Boolean): Long? = ops.bitpos(key, state).awaitFirstOrNull() + + /** + * Find first bit set or clear in a string. + * + * @param key the key. + * @param state the bit type: long. + * @param start the start type: long. + * @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request. + * + * If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is + * returned. + * + * If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns + * the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the + * command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1. + * + * Basically the function consider the right of the string as padded with zeros if you look for clear bits and + * specify no range or the start argument only. + * @since 5.0.1 + * + **/ + override suspend fun bitpos(key: K?, state: Boolean, start: Long): Long? = ops.bitpos(key, state, start).awaitFirstOrNull() + + /** + * Find first bit set or clear in a string. + * + * @param key the key. + * @param state the bit type: long. + * @param start the start type: long. + * @param end the end type: long. + * @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request. + * + * If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is + * returned. + * + * If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns + * the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the + * command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1. + * + * Basically the function consider the right of the string as padded with zeros if you look for clear bits and + * specify no range or the start argument only. + * + * However this behavior changes if you are looking for clear bits and specify a range with both + * start and end. If no clear bit is found in the specified range, the function + * returns -1 as the user specified a clear range and there are no 0 bits in that range. + * + **/ + override suspend fun bitpos(key: K?, state: Boolean, start: Long, end: Long): Long? = ops.bitpos(key, state, start, end).awaitFirstOrNull() + + /** + * Perform bitwise AND between strings. + * + * @param destination result key of the operation. + * @param keys operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + override suspend fun bitopAnd(destination: K?, vararg keys: K?): Long? = ops.bitopAnd(destination, *keys).awaitFirstOrNull() + + /** + * Perform bitwise NOT between strings. + * + * @param destination result key of the operation. + * @param source operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + override suspend fun bitopNot(destination: K?, source: K?): Long? = ops.bitopNot(destination, source).awaitFirstOrNull() + + /** + * Perform bitwise OR between strings. + * + * @param destination result key of the operation. + * @param keys operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + override suspend fun bitopOr(destination: K?, vararg keys: K?): Long? = ops.bitopOr(destination, *keys).awaitFirstOrNull() + + /** + * Perform bitwise XOR between strings. + * + * @param destination result key of the operation. + * @param keys operation input key names. + * @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest + * input string. + * + **/ + override suspend fun bitopXor(destination: K?, vararg keys: K?): Long? = ops.bitopXor(destination, *keys).awaitFirstOrNull() + + /** + * Decrement the integer value of a key by one. + * + * @param key the key. + * @return Long integer-reply the value of {@code key} after the decrement. + * + **/ + override suspend fun decr(key: K?): Long? = ops.decr(key).awaitFirstOrNull() + + /** + * Decrement the integer value of a key by the given number. + * + * @param key the key. + * @param amount the decrement type: long. + * @return Long integer-reply the value of {@code key} after the decrement. + * + **/ + override suspend fun decrby(key: K?, amount: Long): Long? = ops.decrby(key, amount).awaitFirstOrNull() + + /** + * Get the value of a key. + * + * @param key the key. + * @return V bulk-string-reply the value of {@code key}, or {@code null} when {@code key} does not exist. + * + **/ + override suspend fun get(key: K?): V? = ops.get(key).awaitFirstOrNull() + + /** + * Returns the bit value at offset in the string value stored at key. + * + * @param key the key. + * @param offset the offset type: long. + * @return Long integer-reply the bit value stored at offset. + * + **/ + override suspend fun getbit(key: K?, offset: Long): Long? = ops.getbit(key, offset).awaitFirstOrNull() + + /** + * Get a substring of the string stored at a key. + * + * @param key the key. + * @param start the start type: long. + * @param end the end type: long. + * @return V bulk-string-reply. + * + **/ + override suspend fun getrange(key: K?, start: Long, end: Long): V? = ops.getrange(key, start, end).awaitFirstOrNull() + + /** + * Set the string value of a key and return its old value. + * + * @param key the key. + * @param value the value. + * @return V bulk-string-reply the old value stored at {@code key}, or {@code null} when {@code key} did not exist. + * + **/ + override suspend fun getset(key: K?, value: V?): V? = ops.getset(key, value).awaitFirstOrNull() + + /** + * Increment the integer value of a key by one. + * + * @param key the key. + * @return Long integer-reply the value of {@code key} after the increment. + * + **/ + override suspend fun incr(key: K?): Long? = ops.incr(key).awaitFirstOrNull() + + /** + * Increment the integer value of a key by the given amount. + * + * @param key the key. + * @param amount the increment type: long. + * @return Long integer-reply the value of {@code key} after the increment. + * + **/ + override suspend fun incrby(key: K?, amount: Long): Long? = ops.incrby(key, amount).awaitFirstOrNull() + + /** + * Increment the float value of a key by the given amount. + * + * @param key the key. + * @param amount the increment type: double. + * @return Double bulk-string-reply the value of {@code key} after the increment. + * + **/ + override suspend fun incrbyfloat(key: K?, amount: Double): Double? = ops.incrbyfloat(key, amount).awaitFirstOrNull() + + /** + * Get the values of all the given keys. + * + * @param keys the key. + * @return List array-reply list of values at the specified keys. + * + **/ + override suspend fun mget(vararg keys: K?): List>? = ops.mget(*keys).collectList().awaitFirstOrNull() + + /** + * Stream over the values of all the given keys. + * + * @param channel the channel. + * @param keys the keys. + * @return Long array-reply list of values at the specified keys. + * + **/ + override suspend fun mget(channel: KeyValueStreamingChannel?, vararg keys: K?): Long? = ops.mget(channel, *keys).awaitFirstOrNull() + + /** + * Set multiple keys to multiple values. + * + * @param map the null. + * @return String simple-string-reply always {@code OK} since {@code MSET} can't fail. + * + **/ + override suspend fun mset(map: Map?): String? = ops.mset(map).awaitFirstOrNull() + + /** + * Set multiple keys to multiple values, only if none of the keys exist. + * + * @param map the null. + * @return Boolean integer-reply specifically: + * + * {@code 1} if the all the keys were set. {@code 0} if no key was set (at least one key already existed). + * + **/ + override suspend fun msetnx(map: Map?): Boolean? = ops.msetnx(map).awaitFirstOrNull() + + /** + * Set the string value of a key. + * + * @param key the key. + * @param value the value. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. + * + **/ + override suspend fun set(key: K?, value: V?): String? = ops.set(key, value).awaitFirstOrNull() + + /** + * Set the string value of a key. + * + * @param key the key. + * @param value the value. + * @param setArgs the setArgs. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. + * + **/ + override suspend fun set(key: K?, value: V?, setArgs: SetArgs?): String? = ops.set(key, value, setArgs).awaitFirstOrNull() + + /** + * Sets or clears the bit at offset in the string value stored at key. + * + * @param key the key. + * @param offset the offset type: long. + * @param value the value type: string. + * @return Long integer-reply the original bit value stored at offset. + * + **/ + override suspend fun setbit(key: K?, offset: Long, value: Int): Long? = ops.setbit(key, offset, value).awaitFirstOrNull() + + /** + * Set the value and expiration of a key. + * + * @param key the key. + * @param seconds the seconds type: long. + * @param value the value. + * @return String simple-string-reply. + * + **/ + override suspend fun setex(key: K?, seconds: Long, value: V?): String? = ops.setex(key, seconds, value).awaitFirstOrNull() + + /** + * Set the value and expiration in milliseconds of a key. + * + * @param key the key. + * @param milliseconds the milliseconds type: long. + * @param value the value. + * @return String simple-string-reply. + * + **/ + override suspend fun psetex(key: K?, milliseconds: Long, value: V?): String? = ops.psetex(key, milliseconds, value).awaitFirstOrNull() + + /** + * Set the value of a key, only if the key does not exist. + * + * @param key the key. + * @param value the value. + * @return Boolean integer-reply specifically: + * + * {@code 1} if the key was set {@code 0} if the key was not set. + * + **/ + override suspend fun setnx(key: K?, value: V?): Boolean? = ops.setnx(key, value).awaitFirstOrNull() + + /** + * Overwrite part of a string at key starting at the specified offset. + * + * @param key the key. + * @param offset the offset type: long. + * @param value the value. + * @return Long integer-reply the length of the string after it was modified by the command. + * + **/ + override suspend fun setrange(key: K?, offset: Long, value: V?): Long? = ops.setrange(key, offset, value).awaitFirstOrNull() + + /** + * The STRALGO command implements complex algorithms that operate on strings. This method uses the LCS algorithm (longest + * common substring). + * + *
    + *
  • Without modifiers the string representing the longest common substring is returned.
  • + *
  • When {@link StrAlgoArgs#justLen() LEN} is given the command returns the length of the longest common substring.
  • + *
  • When {@link StrAlgoArgs#withIdx() IDX} is given the command returns an array with the LCS length and all the ranges + * in both the strings, start and end offset for each string, where there are matches. When + * {@link StrAlgoArgs#withMatchLen() WITHMATCHLEN} is given each array representing a match will also have the length of the + * match.
  • + *
+ * + * @param strAlgoArgs command arguments. + * @return StringMatchResult. + * @since 6.0 + * + **/ + override suspend fun stralgoLcs(strAlgoArgs: StrAlgoArgs?): StringMatchResult? = ops.stralgoLcs(strAlgoArgs).awaitFirstOrNull() + + /** + * Get the length of the value stored in a key. + * + * @param key the key. + * @return Long integer-reply the length of the string at {@code key}, or {@code 0} when {@code key} does not exist. + * + **/ + override suspend fun strlen(key: K?): Long? = ops.strlen(key).awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisSuspendableReactiveCommandsImpl.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisSuspendableReactiveCommandsImpl.kt new file mode 100644 index 0000000000..1b3fc10cc7 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisSuspendableReactiveCommandsImpl.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2011-2020 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. + */ +@file:Suppress("unused", "UsePropertyAccessSyntax") + +package io.lettuce.core.api.coroutines.reactive + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.api.StatefulRedisConnection +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.api.reactive.RedisReactiveCommands +import kotlinx.coroutines.reactive.awaitFirstOrNull + +/** + * A complete reactive and thread-safe Redis API with 400+ Methods. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + **/ +@ExperimentalLettuceCoroutinesApi +open class RedisSuspendableReactiveCommandsImpl( + private val ops: RedisReactiveCommands, +) : RedisSuspendableCommands, + BaseRedisSuspendableCommands by BaseRedisSuspendableReactiveCommands(ops), + RedisGeoSuspendableCommands by RedisGeoSuspendableReactiveCommands(ops), + RedisHashSuspendableCommands by RedisHashSuspendableReactiveCommands(ops), + RedisHLLSuspendableCommands by RedisHLLSuspendableReactiveCommands(ops), + RedisKeySuspendableCommands by RedisKeySuspendableReactiveCommands(ops), + RedisListSuspendableCommands by RedisListSuspendableReactiveCommands(ops), + RedisScriptingSuspendableCommands by RedisScriptingSuspendableReactiveCommands(ops), + RedisServerSuspendableCommands by RedisServerSuspendableReactiveCommands(ops), + RedisSetSuspendableCommands by RedisSetSuspendableReactiveCommands(ops), + RedisSortedSetSuspendableCommands by RedisSortedSetSuspendableReactiveCommands(ops), + RedisStreamSuspendableCommands by RedisStreamSuspendableReactiveCommands(ops), + RedisStringSuspendableCommands by RedisStringSuspendableReactiveCommands(ops), + RedisTransactionalSuspendableCommands by RedisTransactionalSuspendableReactiveCommands(ops) { + + /** + * Authenticate to the server. + * + * @param password the password + * @return String simple-string-reply + */ + override suspend fun auth(password: CharSequence?): String? = ops.auth(password).awaitFirstOrNull() + + /** + * Authenticate to the server with username and password. Requires Redis 6 or newer. + * + * @param username the username + * @param password the password + * @return String simple-string-reply + * @since 6.0 + */ + override suspend fun auth(username: String?, password: CharSequence?): String? = ops.auth(username, password).awaitFirstOrNull() + + /** + * Change the selected database for the current connection. + * + * @param db the database number + * @return String simple-string-reply + */ + override suspend fun select(db: Int): String? = ops.select(db).awaitFirstOrNull() + + /** + * Swap two Redis databases, so that immediately all the clients connected to a given DB will see the data of the other DB, + * and the other way around + * + * @param db1 the first database number + * @param db2 the second database number + * @return String simple-string-reply + */ + override suspend fun swapdb(db1: Int, db2: Int): String? = ops.swapdb(db1, db2).awaitFirstOrNull() + + /** + * @return the underlying connection. + */ + override val statefulConnection: StatefulRedisConnection = ops.statefulConnection +} \ No newline at end of file diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisTransactionalSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisTransactionalSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..dea43720a6 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/reactive/RedisTransactionalSuspendableReactiveCommands.kt @@ -0,0 +1,89 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.TransactionResult + + +/** + * Coroutine executed commands (based on reactive commands) for Transactions. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisTransactionalSuspendableReactiveCommands(private val ops: RedisTransactionalReactiveCommands) : RedisTransactionalSuspendableCommands { + + /** + * Discard all commands issued after MULTI. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun discard(): String? = ops.discard().awaitFirstOrNull() + + /** + * Execute all commands issued after MULTI. + * + * @return List array-reply each element being the reply to each of the commands in the atomic transaction. + * + * When using {@code WATCH}, {@code EXEC} can return a {@link TransactionResult#wasDiscarded discarded + * TransactionResult}. + * @see TransactionResult#wasDiscarded + * + **/ + override suspend fun exec(): TransactionResult? = ops.exec().awaitFirstOrNull() + + /** + * Mark the start of a transaction block. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun multi(): String? = ops.multi().awaitFirstOrNull() + + /** + * Watch the given keys to determine execution of the MULTI/EXEC block. + * + * @param keys the key. + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun watch(vararg keys: K?): String? = ops.watch(*keys).awaitFirstOrNull() + + /** + * Forget about all watched keys. + * + * @return String simple-string-reply always {@code OK}. + * + **/ + override suspend fun unwatch(): String? = ops.unwatch().awaitFirstOrNull() + +} + diff --git a/src/main/kotlin/io/lettuce/core/api/reactive/RedisReactiveCommandsExtensions.kt b/src/main/kotlin/io/lettuce/core/api/reactive/RedisReactiveCommandsExtensions.kt new file mode 100644 index 0000000000..208c881f73 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/reactive/RedisReactiveCommandsExtensions.kt @@ -0,0 +1,16 @@ +package io.lettuce.core.api.reactive + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.api.coroutines.RedisSuspendableCommands +import io.lettuce.core.api.coroutines.reactive.RedisSuspendableReactiveCommandsImpl + +/** + * Extension for [RedisReactiveCommands] to create [RedisSuspendableCommands] + * + * @author Mikhael Sokolov + * @since 6.0 + */ +@ExperimentalLettuceCoroutinesApi +fun RedisReactiveCommands.asSuspendable(): RedisSuspendableCommands { + return RedisSuspendableReactiveCommandsImpl(this) +} \ No newline at end of file diff --git a/src/main/kotlin/io/lettuce/core/api/sync/RedisSyncCommandsExtensions.kt b/src/main/kotlin/io/lettuce/core/api/sync/RedisSyncCommandsExtensions.kt new file mode 100644 index 0000000000..0bf90286a7 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/api/sync/RedisSyncCommandsExtensions.kt @@ -0,0 +1,21 @@ +package io.lettuce.core.api.sync + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import io.lettuce.core.TransactionResult + +/** + * Allows to create transaction DSL block with [RedisCommands]. + * + * @author Mikhael Sokolov + * @since 6.0 + */ +@ExperimentalLettuceCoroutinesApi +inline fun RedisCommands.multi(action: RedisCommands.() -> Unit): TransactionResult? { + multi() + runCatching { + action.invoke(this) + }.onFailure { + discard() + } + return exec() +} \ No newline at end of file diff --git a/src/main/kotlin/io/lettuce/core/sentinel/api/coroutines/RedisSentinelSuspendableCommands.kt b/src/main/kotlin/io/lettuce/core/sentinel/api/coroutines/RedisSentinelSuspendableCommands.kt new file mode 100644 index 0000000000..83142a5969 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/sentinel/api/coroutines/RedisSentinelSuspendableCommands.kt @@ -0,0 +1,218 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.sentinel.api.coroutines + +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import java.net.SocketAddress +import io.lettuce.core.KillArgs +import io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection + + +/** + * Coroutine executed commands for Redis Sentinel. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + **/ +@ExperimentalLettuceCoroutinesApi +interface RedisSentinelSuspendableCommands { + + /** + * Return the ip and port number of the master with that name. + * + * @param key the key. + * @return SocketAddress;. + * + **/ + suspend fun getMasterAddrByName(key: K?): SocketAddress? + + /** + * Enumerates all the monitored masters and their states. + * + * @return Map>. + * + **/ + suspend fun masters(): List>? + + /** + * Show the state and info of the specified master. + * + * @param key the key. + * @return Map. + * + **/ + suspend fun master(key: K?): Map? + + /** + * Provides a list of replicas for the master with the specified name. + * + * @param key the key. + * @return List>. + * + **/ + suspend fun slaves(key: K?): List>? + + /** + * This command will reset all the masters with matching name. + * + * @param key the key. + * @return Long. + * + **/ + suspend fun reset(key: K?): Long? + + /** + * Perform a failover. + * + * @param key the master id. + * @return String. + * + **/ + suspend fun failover(key: K?): String? + + /** + * This command tells the Sentinel to start monitoring a new master with the specified name, ip, port, and quorum. + * + * @param key the key. + * @param ip the IP address. + * @param port the port. + * @param quorum the quorum count. + * @return String. + * + **/ + suspend fun monitor(key: K?, ip: String?, port: Int, quorum: Int): String? + + /** + * Multiple option / value pairs can be specified (or none at all). + * + * @param key the key. + * @param option the option. + * @param value the value. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. + * + **/ + suspend fun set(key: K?, option: String?, value: V?): String? + + /** + * remove the specified master. + * + * @param key the key. + * @return String. + * + **/ + suspend fun remove(key: K?): String? + + /** + * Get the current connection name. + * + * @return K bulk-string-reply The connection name, or a null bulk reply if no name is set. + * + **/ + suspend fun clientGetname(): K? + + /** + * Set the current connection name. + * + * @param name the client name. + * @return simple-string-reply {@code OK} if the connection name was successfully set. + * + **/ + suspend fun clientSetname(name: K?): String? + + /** + * Kill the connection of a client identified by ip:port. + * + * @param addr ip:port. + * @return String simple-string-reply {@code OK} if the connection exists and has been closed. + * + **/ + suspend fun clientKill(addr: String?): String? + + /** + * Kill connections of clients which are filtered by {@code killArgs}. + * + * @param killArgs args for the kill operation. + * @return Long integer-reply number of killed connections. + * + **/ + suspend fun clientKill(killArgs: KillArgs?): Long? + + /** + * Stop processing commands from clients for some time. + * + * @param timeout the timeout value in milliseconds. + * @return String simple-string-reply The command returns OK or an error if the timeout is invalid. + * + **/ + suspend fun clientPause(timeout: Long): String? + + /** + * Get the list of client connections. + * + * @return String bulk-string-reply a unique string, formatted as follows: One client connection per line (separated by LF), + * each line is composed of a succession of property=value fields separated by a space character. + * + **/ + suspend fun clientList(): String? + + /** + * Get information and statistics about the server. + * + * @return String bulk-string-reply as a collection of text lines. + * + **/ + suspend fun info(): String? + + /** + * Get information and statistics about the server. + * + * @param section the section type: string. + * @return String bulk-string-reply as a collection of text lines. + * + **/ + suspend fun info(section: String?): String? + + /** + * Ping the server. + * + * @return String simple-string-reply. + * + **/ + suspend fun ping(): String? + + /** + * + * @return @code true} if the connection is open (connected and not closed). + * + **/ + suspend fun isOpen(): Boolean + + /** + * + * @return the underlying connection. + * + **/ + suspend fun getStatefulConnection(): StatefulRedisSentinelConnection? + +} + diff --git a/src/main/kotlin/io/lettuce/core/sentinel/api/coroutines/async/RedisSentinelSuspendableAsyncCommands.kt b/src/main/kotlin/io/lettuce/core/sentinel/api/coroutines/async/RedisSentinelSuspendableAsyncCommands.kt new file mode 100644 index 0000000000..4f13f0ad6d --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/sentinel/api/coroutines/async/RedisSentinelSuspendableAsyncCommands.kt @@ -0,0 +1,223 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.sentinel.api.coroutines.async + +import kotlinx.coroutines.future.await +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.async.* +import io.lettuce.core.sentinel.api.async.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import java.net.SocketAddress +import io.lettuce.core.KillArgs +import io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection + + +/** + * Coroutine executed commands (based on async commands) for Redis Sentinel. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesAsyncImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisSentinelSuspendableAsyncCommands(private val ops: RedisSentinelAsyncCommands) : RedisSentinelSuspendableCommands { + + /** + * Return the ip and port number of the master with that name. + * + * @param key the key. + * @return SocketAddress;. + * + **/ + override suspend fun getMasterAddrByName(key: K?): SocketAddress? = ops.getMasterAddrByName(key).await() + + /** + * Enumerates all the monitored masters and their states. + * + * @return Map>. + * + **/ + override suspend fun masters(): List>? = ops.masters().await() + + /** + * Show the state and info of the specified master. + * + * @param key the key. + * @return Map. + * + **/ + override suspend fun master(key: K?): Map? = ops.master(key).await() + + /** + * Provides a list of replicas for the master with the specified name. + * + * @param key the key. + * @return List>. + * + **/ + override suspend fun slaves(key: K?): List>? = ops.slaves(key).await() + + /** + * This command will reset all the masters with matching name. + * + * @param key the key. + * @return Long. + * + **/ + override suspend fun reset(key: K?): Long? = ops.reset(key).await() + + /** + * Perform a failover. + * + * @param key the master id. + * @return String. + * + **/ + override suspend fun failover(key: K?): String? = ops.failover(key).await() + + /** + * This command tells the Sentinel to start monitoring a new master with the specified name, ip, port, and quorum. + * + * @param key the key. + * @param ip the IP address. + * @param port the port. + * @param quorum the quorum count. + * @return String. + * + **/ + override suspend fun monitor(key: K?, ip: String?, port: Int, quorum: Int): String? = ops.monitor(key, ip, port, quorum).await() + + /** + * Multiple option / value pairs can be specified (or none at all). + * + * @param key the key. + * @param option the option. + * @param value the value. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. + * + **/ + override suspend fun set(key: K?, option: String?, value: V?): String? = ops.set(key, option, value).await() + + /** + * remove the specified master. + * + * @param key the key. + * @return String. + * + **/ + override suspend fun remove(key: K?): String? = ops.remove(key).await() + + /** + * Get the current connection name. + * + * @return K bulk-string-reply The connection name, or a null bulk reply if no name is set. + * + **/ + override suspend fun clientGetname(): K? = ops.clientGetname().await() + + /** + * Set the current connection name. + * + * @param name the client name. + * @return simple-string-reply {@code OK} if the connection name was successfully set. + * + **/ + override suspend fun clientSetname(name: K?): String? = ops.clientSetname(name).await() + + /** + * Kill the connection of a client identified by ip:port. + * + * @param addr ip:port. + * @return String simple-string-reply {@code OK} if the connection exists and has been closed. + * + **/ + override suspend fun clientKill(addr: String?): String? = ops.clientKill(addr).await() + + /** + * Kill connections of clients which are filtered by {@code killArgs}. + * + * @param killArgs args for the kill operation. + * @return Long integer-reply number of killed connections. + * + **/ + override suspend fun clientKill(killArgs: KillArgs?): Long? = ops.clientKill(killArgs).await() + + /** + * Stop processing commands from clients for some time. + * + * @param timeout the timeout value in milliseconds. + * @return String simple-string-reply The command returns OK or an error if the timeout is invalid. + * + **/ + override suspend fun clientPause(timeout: Long): String? = ops.clientPause(timeout).await() + + /** + * Get the list of client connections. + * + * @return String bulk-string-reply a unique string, formatted as follows: One client connection per line (separated by LF), + * each line is composed of a succession of property=value fields separated by a space character. + * + **/ + override suspend fun clientList(): String? = ops.clientList().await() + + /** + * Get information and statistics about the server. + * + * @return String bulk-string-reply as a collection of text lines. + * + **/ + override suspend fun info(): String? = ops.info().await() + + /** + * Get information and statistics about the server. + * + * @param section the section type: string. + * @return String bulk-string-reply as a collection of text lines. + * + **/ + override suspend fun info(section: String?): String? = ops.info(section).await() + + /** + * Ping the server. + * + * @return String simple-string-reply. + * + **/ + override suspend fun ping(): String? = ops.ping().await() + + /** + * + * @return @code true} if the connection is open (connected and not closed). + * + **/ + override suspend fun isOpen(): Boolean = ops.isOpen() + + /** + * + * @return the underlying connection. + * + **/ + override suspend fun getStatefulConnection(): StatefulRedisSentinelConnection? = ops.getStatefulConnection() + +} + diff --git a/src/main/kotlin/io/lettuce/core/sentinel/api/coroutines/reactive/RedisSentinelSuspendableReactiveCommands.kt b/src/main/kotlin/io/lettuce/core/sentinel/api/coroutines/reactive/RedisSentinelSuspendableReactiveCommands.kt new file mode 100644 index 0000000000..c561d2b2e1 --- /dev/null +++ b/src/main/kotlin/io/lettuce/core/sentinel/api/coroutines/reactive/RedisSentinelSuspendableReactiveCommands.kt @@ -0,0 +1,223 @@ +/* + * Copyright 2017-2020 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. + */ + +@file:Suppress("unused") + +package io.lettuce.core.sentinel.api.coroutines.reactive + +import kotlinx.coroutines.reactive.awaitFirstOrNull +import io.lettuce.core.api.coroutines.* +import io.lettuce.core.sentinel.api.coroutines.* +import io.lettuce.core.api.reactive.* +import io.lettuce.core.sentinel.api.reactive.* +import io.lettuce.core.ExperimentalLettuceCoroutinesApi +import java.net.SocketAddress +import io.lettuce.core.KillArgs +import io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection + + +/** + * Coroutine executed commands (based on reactive commands) for Redis Sentinel. + * + * @param Key type. + * @param Value type. + * @author Mikhael Sokolov + * @since 6.0 + * + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesReactiveImplementation + **/ +@ExperimentalLettuceCoroutinesApi +internal class RedisSentinelSuspendableReactiveCommands(private val ops: RedisSentinelReactiveCommands) : RedisSentinelSuspendableCommands { + + /** + * Return the ip and port number of the master with that name. + * + * @param key the key. + * @return SocketAddress;. + * + **/ + override suspend fun getMasterAddrByName(key: K?): SocketAddress? = ops.getMasterAddrByName(key).awaitFirstOrNull() + + /** + * Enumerates all the monitored masters and their states. + * + * @return Map>. + * + **/ + override suspend fun masters(): List>? = ops.masters().collectList().awaitFirstOrNull() + + /** + * Show the state and info of the specified master. + * + * @param key the key. + * @return Map. + * + **/ + override suspend fun master(key: K?): Map? = ops.master(key).awaitFirstOrNull() + + /** + * Provides a list of replicas for the master with the specified name. + * + * @param key the key. + * @return List>. + * + **/ + override suspend fun slaves(key: K?): List>? = ops.slaves(key).collectList().awaitFirstOrNull() + + /** + * This command will reset all the masters with matching name. + * + * @param key the key. + * @return Long. + * + **/ + override suspend fun reset(key: K?): Long? = ops.reset(key).awaitFirstOrNull() + + /** + * Perform a failover. + * + * @param key the master id. + * @return String. + * + **/ + override suspend fun failover(key: K?): String? = ops.failover(key).awaitFirstOrNull() + + /** + * This command tells the Sentinel to start monitoring a new master with the specified name, ip, port, and quorum. + * + * @param key the key. + * @param ip the IP address. + * @param port the port. + * @param quorum the quorum count. + * @return String. + * + **/ + override suspend fun monitor(key: K?, ip: String?, port: Int, quorum: Int): String? = ops.monitor(key, ip, port, quorum).awaitFirstOrNull() + + /** + * Multiple option / value pairs can be specified (or none at all). + * + * @param key the key. + * @param option the option. + * @param value the value. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. + * + **/ + override suspend fun set(key: K?, option: String?, value: V?): String? = ops.set(key, option, value).awaitFirstOrNull() + + /** + * remove the specified master. + * + * @param key the key. + * @return String. + * + **/ + override suspend fun remove(key: K?): String? = ops.remove(key).awaitFirstOrNull() + + /** + * Get the current connection name. + * + * @return K bulk-string-reply The connection name, or a null bulk reply if no name is set. + * + **/ + override suspend fun clientGetname(): K? = ops.clientGetname().awaitFirstOrNull() + + /** + * Set the current connection name. + * + * @param name the client name. + * @return simple-string-reply {@code OK} if the connection name was successfully set. + * + **/ + override suspend fun clientSetname(name: K?): String? = ops.clientSetname(name).awaitFirstOrNull() + + /** + * Kill the connection of a client identified by ip:port. + * + * @param addr ip:port. + * @return String simple-string-reply {@code OK} if the connection exists and has been closed. + * + **/ + override suspend fun clientKill(addr: String?): String? = ops.clientKill(addr).awaitFirstOrNull() + + /** + * Kill connections of clients which are filtered by {@code killArgs}. + * + * @param killArgs args for the kill operation. + * @return Long integer-reply number of killed connections. + * + **/ + override suspend fun clientKill(killArgs: KillArgs?): Long? = ops.clientKill(killArgs).awaitFirstOrNull() + + /** + * Stop processing commands from clients for some time. + * + * @param timeout the timeout value in milliseconds. + * @return String simple-string-reply The command returns OK or an error if the timeout is invalid. + * + **/ + override suspend fun clientPause(timeout: Long): String? = ops.clientPause(timeout).awaitFirstOrNull() + + /** + * Get the list of client connections. + * + * @return String bulk-string-reply a unique string, formatted as follows: One client connection per line (separated by LF), + * each line is composed of a succession of property=value fields separated by a space character. + * + **/ + override suspend fun clientList(): String? = ops.clientList().awaitFirstOrNull() + + /** + * Get information and statistics about the server. + * + * @return String bulk-string-reply as a collection of text lines. + * + **/ + override suspend fun info(): String? = ops.info().awaitFirstOrNull() + + /** + * Get information and statistics about the server. + * + * @param section the section type: string. + * @return String bulk-string-reply as a collection of text lines. + * + **/ + override suspend fun info(section: String?): String? = ops.info(section).awaitFirstOrNull() + + /** + * Ping the server. + * + * @return String simple-string-reply. + * + **/ + override suspend fun ping(): String? = ops.ping().awaitFirstOrNull() + + /** + * + * @return @code true} if the connection is open (connected and not closed). + * + **/ + override suspend fun isOpen(): Boolean = ops.isOpen() + + /** + * + * @return the underlying connection. + * + **/ + override suspend fun getStatefulConnection(): StatefulRedisSentinelConnection? = ops.getStatefulConnection() + +} + diff --git a/src/main/templates/io/lettuce/core/api/RedisStreamCommands.java b/src/main/templates/io/lettuce/core/api/RedisStreamCommands.java index b3810c4cd7..fe00dce798 100644 --- a/src/main/templates/io/lettuce/core/api/RedisStreamCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisStreamCommands.java @@ -23,6 +23,8 @@ import io.lettuce.core.Range; import io.lettuce.core.StreamMessage; import io.lettuce.core.XAddArgs; +import io.lettuce.core.XGroupCreateArgs; +import io.lettuce.core.XReadArgs; import io.lettuce.core.XClaimArgs; import io.lettuce.core.XReadArgs.StreamOffset; import io.lettuce.core.models.stream.PendingMessage; diff --git a/src/main/templates/io/lettuce/core/api/RedisStringCommands.java b/src/main/templates/io/lettuce/core/api/RedisStringCommands.java index 5ed72d4234..87c34b4aa4 100644 --- a/src/main/templates/io/lettuce/core/api/RedisStringCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisStringCommands.java @@ -21,6 +21,8 @@ import io.lettuce.core.BitFieldArgs; import io.lettuce.core.KeyValue; import io.lettuce.core.SetArgs; +import io.lettuce.core.StrAlgoArgs; +import io.lettuce.core.StringMatchResult; import io.lettuce.core.output.KeyValueStreamingChannel; /** diff --git a/src/test/java/io/lettuce/apigenerator/CompilationUnitFactory.java b/src/test/java/io/lettuce/apigenerator/CompilationUnitFactory.java index c63f24f107..ebb1427489 100644 --- a/src/test/java/io/lettuce/apigenerator/CompilationUnitFactory.java +++ b/src/test/java/io/lettuce/apigenerator/CompilationUnitFactory.java @@ -102,8 +102,7 @@ public void createInterface() throws Exception { } } - resultType.setComment(new JavadocComment(typeDocFunction.apply(templateTypeDeclaration.getComment().orElse(null) - .getContent()))); + resultType.setComment(new JavadocComment(typeDocFunction.apply(templateTypeDeclaration.getComment().get().getContent()))); result.setComment(template.getComment().orElse(null)); result.setImports(new NodeList<>()); diff --git a/src/test/java/io/lettuce/apigenerator/Constants.java b/src/test/java/io/lettuce/apigenerator/Constants.java index 2996b2097b..93f219bb7b 100644 --- a/src/test/java/io/lettuce/apigenerator/Constants.java +++ b/src/test/java/io/lettuce/apigenerator/Constants.java @@ -22,8 +22,24 @@ */ class Constants { - public static final String[] TEMPLATE_NAMES = { "RedisStreamCommands" }; + public static final String[] TEMPLATE_NAMES = { + "BaseRedisCommands", + "RedisGeoCommands", + "RedisHashCommands", + "RedisHLLCommands", + "RedisKeyCommands", + "RedisListCommands", + "RedisScriptingCommands", + "RedisSentinelCommands", + "RedisServerCommands", + "RedisSetCommands", + "RedisSortedSetCommands", + "RedisStreamCommands", + "RedisStringCommands", + "RedisTransactionalCommands" + }; public static final File TEMPLATES = new File("src/main/templates"); public static final File SOURCES = new File("src/main/java"); + public static final File KOTLIN_SOURCES = new File("src/main/kotlin"); } diff --git a/src/test/java/io/lettuce/apigenerator/CreateAsyncApi.java b/src/test/java/io/lettuce/apigenerator/CreateAsyncApi.java index 7589cc5f85..d42ea0bf32 100644 --- a/src/test/java/io/lettuce/apigenerator/CreateAsyncApi.java +++ b/src/test/java/io/lettuce/apigenerator/CreateAsyncApi.java @@ -15,6 +15,13 @@ */ package io.lettuce.apigenerator; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.type.Type; +import io.lettuce.core.internal.LettuceSets; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -23,15 +30,6 @@ import java.util.function.Function; import java.util.function.Supplier; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.type.Type; - -import io.lettuce.core.internal.LettuceSets; - /** * Create async API based on the templates. * @@ -40,18 +38,16 @@ @RunWith(Parameterized.class) public class CreateAsyncApi { - private Set KEEP_METHOD_RESULT_TYPE = LettuceSets.unmodifiableSet("shutdown", "debugOom", "debugSegfault", - "digest", "close", "isOpen", "BaseRedisCommands.reset", "getStatefulConnection", "setAutoFlushCommands", - "flushCommands"); + public static final Set KEEP_METHOD_RESULT_TYPE = LettuceSets.unmodifiableSet("shutdown", "debugOom", "debugSegfault", "digest", "close", "isOpen", "BaseRedisCommands.reset", "getStatefulConnection", "setAutoFlushCommands", "flushCommands"); - private CompilationUnitFactory factory; + private final CompilationUnitFactory factory; @Parameterized.Parameters(name = "Create {0}") public static List arguments() { List result = new ArrayList<>(); for (String templateName : Constants.TEMPLATE_NAMES) { - result.add(new Object[] { templateName }); + result.add(new Object[]{templateName}); } return result; diff --git a/src/test/java/io/lettuce/apigenerator/CreateKotlinCoroutinesApi.java b/src/test/java/io/lettuce/apigenerator/CreateKotlinCoroutinesApi.java new file mode 100644 index 0000000000..d144c29831 --- /dev/null +++ b/src/test/java/io/lettuce/apigenerator/CreateKotlinCoroutinesApi.java @@ -0,0 +1,106 @@ +/* + * Copyright 2011-2020 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 io.lettuce.apigenerator; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; +import java.util.function.Supplier; + +import static io.lettuce.apigenerator.Constants.*; +import static java.util.stream.Collectors.toList; + +/** + * Create coroutine-reactive API based on the templates. + * + * @author Mikhael Sokolov + */ +@RunWith(Parameterized.class) +public class CreateKotlinCoroutinesApi { + + private final KotlinCompilationUnitFactory factory; + + @Parameters(name = "Create {0}") + public static List arguments() { + return Arrays + .stream(TEMPLATE_NAMES) + .map(t -> new Object[]{t}) + .collect(toList()); + } + + /** + * @param templateName + */ + public CreateKotlinCoroutinesApi(String templateName) { + + String targetName = templateName.replace("Commands", "SuspendableCommands"); + File templateFile = new File(TEMPLATES, "io/lettuce/core/api/" + templateName + ".java"); + String targetPackage; + + if (templateName.contains("RedisSentinel")) { + targetPackage = "io.lettuce.core.sentinel.api.coroutines"; + } else { + targetPackage = "io.lettuce.core.api.coroutines"; + } + + factory = new KotlinCompilationUnitFactory( + templateFile, + KOTLIN_SOURCES, + targetPackage, + targetName, + null, + null, + importSupplier(), + commentInjector(), + null + ); + } + + /** + * Supply additional imports. + * + * @return + */ + Supplier> importSupplier() { + return () -> Collections.singletonList("io.lettuce.core.ExperimentalLettuceCoroutinesApi"); + } + + + /** + * Mutate type comment. + * + * @return + */ + Function commentInjector() { + return s -> s + .replaceAll("\\$\\{intent}", "Coroutine executed commands") + .replaceAll("\\$\\{author}", "Mikhael Sokolov") + .replaceAll("\\$\\{since}", "6.0") + .replaceAll("\\$\\{generator}", getClass().getName()); + } + + @Test + public void createInterface() throws Exception { + factory.create(); + } +} diff --git a/src/test/java/io/lettuce/apigenerator/CreateKotlinCoroutinesAsyncImplementation.java b/src/test/java/io/lettuce/apigenerator/CreateKotlinCoroutinesAsyncImplementation.java new file mode 100644 index 0000000000..7fe44ea771 --- /dev/null +++ b/src/test/java/io/lettuce/apigenerator/CreateKotlinCoroutinesAsyncImplementation.java @@ -0,0 +1,135 @@ +/* + * Copyright 2011-2020 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 io.lettuce.apigenerator; + +import com.github.javaparser.ast.body.MethodDeclaration; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.util.function.Function; +import java.util.function.Supplier; + +import static io.lettuce.apigenerator.CompilationUnitFactory.contains; +import static io.lettuce.apigenerator.Constants.*; +import static io.lettuce.apigenerator.CreateAsyncApi.KEEP_METHOD_RESULT_TYPE; +import static java.util.stream.Collectors.toList; + +/** + * Create coroutine-reactive API based on the templates. + * + * @author Mikhael Sokolov + */ +@RunWith(Parameterized.class) +public class CreateKotlinCoroutinesAsyncImplementation { + + private final KotlinCompilationUnitFactory factory; + + @Parameters(name = "Create {0}") + public static List arguments() { + return Arrays + .stream(TEMPLATE_NAMES) + .map(t -> new Object[]{t}) + .collect(toList()); + } + + /** + * @param templateName + */ + public CreateKotlinCoroutinesAsyncImplementation(String templateName) { + + String targetName = templateName.replace("Commands", "SuspendableAsyncCommands"); + File templateFile = new File(TEMPLATES, "io/lettuce/core/api/" + templateName + ".java"); + String targetPackage; + + if (templateName.contains("RedisSentinel")) { + targetPackage = "io.lettuce.core.sentinel.api.coroutines.async"; + } else { + targetPackage = "io.lettuce.core.api.coroutines.async"; + } + + String ops = templateName.replace("Commands", "AsyncCommands"); + String coroutineInterface = templateName.replace("Commands", "SuspendableCommands"); + + factory = new KotlinCompilationUnitFactory( + templateFile, + KOTLIN_SOURCES, + targetPackage, + targetName, + ops, + coroutineInterface, + defaultImporter(), + commentInjector(), + implMody() + ); + } + + /** + * Supply additional imports. + * + * @return + */ + Supplier> defaultImporter() { + return () -> Arrays.asList( + "kotlinx.coroutines.future.await", + "io.lettuce.core.api.coroutines.*", + "io.lettuce.core.sentinel.api.coroutines.*", + "io.lettuce.core.api.async.*", + "io.lettuce.core.sentinel.api.async.*", + "io.lettuce.core.ExperimentalLettuceCoroutinesApi" + ); + } + + /** + * Generate body + * + * @return + */ + Function implMody() { + return method -> { + if (contains(KEEP_METHOD_RESULT_TYPE, method)) { + return ""; + } else if (method.getTypeAsString().equals("void")) { + return ".await().let { Unit }"; + } else { + return ".await()"; + } + }; + } + + + /** + * Mutate type comment. + * + * @return + */ + Function commentInjector() { + return s -> s + .replaceAll("\\$\\{intent}", "Coroutine executed commands (based on async commands)") + .replaceAll("\\$\\{author}", "Mikhael Sokolov") + .replaceAll("\\$\\{since}", "6.0") + .replaceAll("\\$\\{generator}", getClass().getName()); + } + + @Test + public void createImplementation() throws Exception { + factory.create(); + } +} diff --git a/src/test/java/io/lettuce/apigenerator/CreateKotlinCoroutinesReactiveImplementation.java b/src/test/java/io/lettuce/apigenerator/CreateKotlinCoroutinesReactiveImplementation.java new file mode 100644 index 0000000000..3f424bed7a --- /dev/null +++ b/src/test/java/io/lettuce/apigenerator/CreateKotlinCoroutinesReactiveImplementation.java @@ -0,0 +1,144 @@ +/* + * Copyright 2011-2020 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 io.lettuce.apigenerator; + +import com.github.javaparser.ast.body.MethodDeclaration; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.util.function.Function; +import java.util.function.Supplier; + +import static io.lettuce.apigenerator.CompilationUnitFactory.contains; +import static io.lettuce.apigenerator.Constants.TEMPLATES; +import static io.lettuce.apigenerator.Constants.TEMPLATE_NAMES; +import static io.lettuce.apigenerator.CreateReactiveApi.*; +import static java.util.stream.Collectors.toList; + +/** + * Create coroutine-reactive API based on the templates. + * + * @author Mikhael Sokolov + */ +@RunWith(Parameterized.class) +public class CreateKotlinCoroutinesReactiveImplementation { + + private final KotlinCompilationUnitFactory factory; + + @Parameters(name = "Create {0}") + public static List arguments() { + return Arrays + .stream(TEMPLATE_NAMES) + .map(t -> new Object[]{t}) + .collect(toList()); + } + + /** + * @param templateName + */ + public CreateKotlinCoroutinesReactiveImplementation(String templateName) { + + String targetName = templateName.replace("Commands", "SuspendableReactiveCommands"); + File templateFile = new File(TEMPLATES, "io/lettuce/core/api/" + templateName + ".java"); + String targetPackage; + + if (templateName.contains("RedisSentinel")) { + targetPackage = "io.lettuce.core.sentinel.api.coroutines.reactive"; + } else { + targetPackage = "io.lettuce.core.api.coroutines.reactive"; + } + + String ops = templateName.replace("Commands", "ReactiveCommands"); + String coroutineInterface = templateName.replace("Commands", "SuspendableCommands"); + + factory = new KotlinCompilationUnitFactory( + templateFile, + Constants.KOTLIN_SOURCES, + targetPackage, + targetName, + ops, + coroutineInterface, + defaultImporter(), + commentInjector(), + implBody() + ); + } + + /** + * Supply additional imports. + * + * @return + */ + Supplier> defaultImporter() { + return () -> Arrays.asList( + "kotlinx.coroutines.reactive.awaitFirstOrNull", + "io.lettuce.core.api.coroutines.*", + "io.lettuce.core.sentinel.api.coroutines.*", + "io.lettuce.core.api.reactive.*", + "io.lettuce.core.sentinel.api.reactive.*", + "io.lettuce.core.ExperimentalLettuceCoroutinesApi" + ); + } + + /** + * Generate body + * + * @return + */ + Function implBody() { + return method -> { + if (contains(VALUE_WRAP, method)) { + return ".map { it.value }.collectList().awaitFirstOrNull()"; + } else if (contains(FORCE_FLUX_RESULT, method)) { + return ".awaitFirstOrNull()"; + } else if (contains(KEEP_METHOD_RESULT_TYPE, method)) { + return ""; + } else if (method.getTypeAsString().contains("List<")) { + return ".collectList().awaitFirstOrNull()"; + } else if (method.getTypeAsString().contains("Set<")) { + return ".collectList().awaitFirstOrNull()?.toSet()"; + } else if (method.getTypeAsString().equals("void")) { + return ".awaitFirstOrNull().let { Unit }"; + } else { + return ".awaitFirstOrNull()"; + } + }; + } + + + /** + * Mutate type comment. + * + * @return + */ + Function commentInjector() { + return s -> s + .replaceAll("\\$\\{intent}", "Coroutine executed commands (based on reactive commands)") + .replaceAll("\\$\\{author}", "Mikhael Sokolov") + .replaceAll("\\$\\{since}", "6.0") + .replaceAll("\\$\\{generator}", getClass().getName()); + } + + @Test + public void createImplementation() throws Exception { + factory.create(); + } +} diff --git a/src/test/java/io/lettuce/apigenerator/CreateReactiveApi.java b/src/test/java/io/lettuce/apigenerator/CreateReactiveApi.java index fe5a221ce5..ec3903ecca 100644 --- a/src/test/java/io/lettuce/apigenerator/CreateReactiveApi.java +++ b/src/test/java/io/lettuce/apigenerator/CreateReactiveApi.java @@ -15,21 +15,19 @@ */ package io.lettuce.apigenerator; -import java.io.File; -import java.util.*; -import java.util.function.Function; -import java.util.function.Supplier; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.type.Type; - import io.lettuce.core.internal.LettuceSets; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.File; +import java.util.*; +import java.util.function.Function; +import java.util.function.Supplier; /** * Create reactive API based on the templates. @@ -39,12 +37,9 @@ @RunWith(Parameterized.class) public class CreateReactiveApi { - private static Set KEEP_METHOD_RESULT_TYPE = LettuceSets.unmodifiableSet("digest", "close", "isOpen", - "BaseRedisCommands.reset", "getStatefulConnection", "setAutoFlushCommands", "flushCommands"); - - private static Set FORCE_FLUX_RESULT = LettuceSets.unmodifiableSet("eval", "evalsha", "dispatch"); - - private static Set VALUE_WRAP = LettuceSets.unmodifiableSet("geopos", "bitfield"); + public static Set KEEP_METHOD_RESULT_TYPE = LettuceSets.unmodifiableSet("digest", "close", "isOpen", "BaseRedisCommands.reset", "getStatefulConnection", "setAutoFlushCommands", "flushCommands"); + public static Set FORCE_FLUX_RESULT = LettuceSets.unmodifiableSet("eval", "evalsha", "dispatch"); + public static Set VALUE_WRAP = LettuceSets.unmodifiableSet("geopos", "bitfield"); private static final Map RESULT_SPEC; @@ -57,21 +52,20 @@ public class CreateReactiveApi { RESULT_SPEC = resultSpec; } - private CompilationUnitFactory factory; + private final CompilationUnitFactory factory; @Parameterized.Parameters(name = "Create {0}") public static List arguments() { List result = new ArrayList<>(); for (String templateName : Constants.TEMPLATE_NAMES) { - result.add(new Object[] { templateName }); + result.add(new Object[]{templateName}); } return result; } /** - * * @param templateName */ public CreateReactiveApi(String templateName) { @@ -147,17 +141,16 @@ Function methodTypeMutator() { } - private String getResultType(MethodDeclaration method, - ClassOrInterfaceDeclaration classOfMethod) { + ClassOrInterfaceDeclaration classOfMethod) { - if(RESULT_SPEC.containsKey(method.getName())){ + if (RESULT_SPEC.containsKey(method.getName())) { return RESULT_SPEC.get(method.getName()); } String key = classOfMethod.getName() + "." + method.getName(); - if(RESULT_SPEC.containsKey(key)){ + if (RESULT_SPEC.containsKey(key)) { return RESULT_SPEC.get(key); } diff --git a/src/test/java/io/lettuce/apigenerator/GenerateCommandInterfaces.java b/src/test/java/io/lettuce/apigenerator/GenerateCommandInterfaces.java index bfde68d1ba..80b32e0217 100644 --- a/src/test/java/io/lettuce/apigenerator/GenerateCommandInterfaces.java +++ b/src/test/java/io/lettuce/apigenerator/GenerateCommandInterfaces.java @@ -24,8 +24,16 @@ * @author Mark Paluch */ @RunWith(Suite.class) -@Suite.SuiteClasses({ CreateAsyncApi.class, CreateSyncApi.class, CreateReactiveApi.class, - CreateAsyncNodeSelectionClusterApi.class, CreateSyncNodeSelectionClusterApi.class }) +@Suite.SuiteClasses({ + CreateAsyncApi.class, + CreateSyncApi.class, + CreateReactiveApi.class, + CreateAsyncNodeSelectionClusterApi.class, + CreateSyncNodeSelectionClusterApi.class, + CreateKotlinCoroutinesApi.class, + CreateKotlinCoroutinesAsyncImplementation.class, + CreateKotlinCoroutinesReactiveImplementation.class, +}) public class GenerateCommandInterfaces { } diff --git a/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java b/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java new file mode 100644 index 0000000000..b83d4e8da3 --- /dev/null +++ b/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java @@ -0,0 +1,295 @@ +/* + * Copyright 2011-2020 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 io.lettuce.apigenerator; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.JavaToken; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.type.TypeParameter; +import com.github.javaparser.ast.visitor.VoidVisitorAdapter; +import com.github.javaparser.javadoc.Javadoc; +import io.lettuce.core.internal.LettuceSets; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.function.Function; +import java.util.function.Supplier; + +import static java.util.stream.Collectors.joining; + +/** + * @author Mikhael Sokolov + */ +@SuppressWarnings("OptionalGetWithoutIsPresent") +class KotlinCompilationUnitFactory { + + private static final Set SKIP_IMPORTS = Collections.unmodifiableSet(LettuceSets.newHashSet("java.util.List", "java.util.Set", "java.util.Map")); + private static final String FORMATTING_INDENT = " "; + + private final File templateFile; + private final File target; + private final String targetPackage; + private final String targetName; + + private final String ops; + private final String coroutinesInterface; + private final Supplier> importSupplier; + private final Function commentInjector; + private final Function implBody; + + private final StringBuilder result = new StringBuilder(); + + public KotlinCompilationUnitFactory(File templateFile, + File sources, + String targetPackage, + String targetName, + String opsClass, + String coroutinesInterface, + Supplier> importSupplier, + Function commentInjector, + Function implBody) { + this.templateFile = templateFile; + this.targetPackage = targetPackage; + this.targetName = targetName; + this.ops = opsClass; + this.coroutinesInterface = coroutinesInterface; + this.importSupplier = importSupplier; + this.commentInjector = commentInjector; + this.implBody = implBody; + + this.target = new File(sources, targetPackage.replace('.', '/') + "/" + targetName + ".kt"); + } + + public void create() throws Exception { + CompilationUnit template = JavaParser.parse(templateFile); + + JavaToken license = template.getTokenRange().get().getBegin(); + result.append(license.asString()); + result.append(license.getNextToken().get().asString()); + result.append("\n"); + + result.append("@file:Suppress(\"unused\")").append("\n\n"); + + result.append("package ").append(targetPackage).append("\n\n"); + + importSupplier.get().forEach(l -> result.append("import ").append(l).append("\n")); + + template + .getImports() + .stream() + .filter(i -> SKIP_IMPORTS + .stream() + .noneMatch(si -> si.equals(i.getNameAsString())) + ) + .forEach(i -> result + .append("import ") + .append(i.getNameAsString()) + .append(i.isAsterisk() ? ".*" : "") + .append("\n") + ); + + result.append("\n\n"); + + ClassOrInterfaceDeclaration clazz = (ClassOrInterfaceDeclaration) template.getTypes().get(0); + + result.append(commentInjector.apply(extractJavadoc(clazz.getJavadoc().get()) + .replaceAll("@author Mark Paluch", "@author \\${author}") + .replaceAll("@since [0-9].0", "@since \\${since}") + .replaceAll("\\*\\*/", "* @generated by \\${generator}\r\n **/") + )); + + result.append("@ExperimentalLettuceCoroutinesApi").append("\n"); + + NodeList typeParameters = clazz.getTypeParameters(); + String tp = extractTypeParams(typeParameters); + + if (isInterface()) { + result + .append("interface ") + .append(targetName) + .append(tp) + .append(" "); + } else { + result + .append("internal class ") + .append(targetName) + .append(tp) + .append("(") + .append("private val ops: ") + .append(ops) + .append(tp) + .append(")") + .append(" : ") + .append(coroutinesInterface) + .append(tp) + .append(" "); + } + + + result.append("{\n\n"); + new MethodVisitor().visit(template, null); + result.append("}\n\n"); + + writeResult(); + } + + private class MethodVisitor extends VoidVisitorAdapter { + + @Override + public void visit(MethodDeclaration method, Object arg) { + result + .append(FORMATTING_INDENT) + .append(extractJavadoc(method.getJavadoc().get()).replace("\n", "\n" + FORMATTING_INDENT)) + .append(extractAnnotations(method)) + .append(isInterface() ? "" : "override ") + .append("suspend fun ") + .append(method.getTypeParameters().isNonEmpty() ? extractTypeParams(method.getTypeParameters()).concat(" ") : "") + .append(method.getName()) + .append("(") + .append(extractParameters(method)) + .append(")") + .append(": ") + .append(fixType(method.getType())) + .append(constructBody(method)) + .append("\n\n"); + } + + private String extractAnnotations(MethodDeclaration method) { + return method + .getAnnotations() + .stream() + .map(a -> { + String name = a.getNameAsString(); + if ("Deprecated".equals(name)) { + return "@Deprecated(message = \"Use another API instead.\")" + "\n" + FORMATTING_INDENT; + } else { + return name + "\n" + FORMATTING_INDENT; + } + }) + .collect(joining()); + } + + private String extractParameters(MethodDeclaration method) { + return method + .getParameters() + .stream() + .map(p -> (p.isVarArgs() ? "vararg " : "") + p.getName() + ": " + fixType(p.getType())) + .collect(joining(", ")); + } + + private String fixType(Type type) { + if (type.isArrayType()) { + Type componentType = type.asArrayType().getComponentType(); + if (componentType.asString().equals("byte")) { + return "ByteArray?"; + } else { + return String.format("Array<%s?>?", componentType.asString()); + } + } else if (type.isPrimitiveType()) { + return type + .asPrimitiveType() + .toBoxedType() + .getName() + .asString() + .replace("Integer", "Int") + .replace("Object", "Any?"); + } else { + return type + .asString() + .replace("void", "Unit") + .replace("Object", "Any") + .replace("? extends", "out") + .replace("? super", "in") + .replace(",", ", ") + .concat("?"); + } + } + + private String constructBody(MethodDeclaration method) { + if (isInterface()) { + return ""; + } + StringBuilder body = new StringBuilder().append(" = "); + + String params = method + .getParameters() + .stream() + .map(p -> (p.isVarArgs() ? "*" : "") + p.getNameAsString()) + .collect(joining(", ")); + + String await = implBody.apply(method); + + return body + .append("ops.") + .append(method.getNameAsString()) + .append(extractTypeParams(method.getTypeParameters())) + .append("(") + .append(params) + .append(")") + .append(await) + .toString(); + } + } + + public static String extractTypeParams(NodeList typeParams) { + if (typeParams.isEmpty()) { + return ""; + } else { + return typeParams + .stream() + .map(tp -> tp.getName().getIdentifier()) + .collect(joining(", ", "<", ">")); + } + } + + @SuppressWarnings({"StringBufferReplaceableByString"}) + public static String extractJavadoc(Javadoc javadoc) { + String plainJavadoc = javadoc + .toText() + .replace("\n", "\n" + " * ") + .replace("<", "<") + .replace(">", ">"); + + return new StringBuilder() + .append("/**\n") + .append(" * ") + .append(plainJavadoc) + .append("\n") + .append(" **/") + .append("\n") + .toString(); + } + + private Boolean isInterface() { + return implBody == null; + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + private void writeResult() throws IOException { + target.getParentFile().mkdirs(); + FileOutputStream fos = new FileOutputStream(target); + fos.write(result.toString().getBytes()); + fos.close(); + } +}