From 243d1ccbd55f1c0fc67e08a96759443bef6ccb38 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 9 Mar 2021 14:26:49 +0100 Subject: [PATCH] Polishing #1608 Fix API template by importing FlushMode. Deprecate flushallAsync and flushdbAsync in favor of their variants accepting FlushMode. Let FlushMode implement ProtocolKeyword. Tweak Javadoc. Original pull request: #1646. --- .../core/AbstractRedisAsyncCommands.java | 4 ++-- .../core/AbstractRedisReactiveCommands.java | 4 ++-- src/main/java/io/lettuce/core/FlushMode.java | 23 ++++++++++++++++--- .../io/lettuce/core/RedisCommandBuilder.java | 13 ++--------- .../async/RedisScriptingAsyncCommands.java | 3 ++- .../api/async/RedisServerAsyncCommands.java | 13 ++++++++--- .../RedisScriptingReactiveCommands.java | 5 ++-- .../reactive/RedisServerReactiveCommands.java | 12 +++++++--- .../core/api/sync/RedisScriptingCommands.java | 3 ++- .../core/api/sync/RedisServerCommands.java | 11 +++++++-- .../NodeSelectionScriptingAsyncCommands.java | 3 ++- .../NodeSelectionServerAsyncCommands.java | 11 +++++++-- .../sync/NodeSelectionScriptingCommands.java | 3 ++- .../api/sync/NodeSelectionServerCommands.java | 11 +++++++-- .../RedisScriptingCoroutinesCommands.kt | 3 ++- .../RedisServerCoroutinesCommands.kt | 16 +++++++------ .../core/api/RedisScriptingCommands.java | 4 +++- .../lettuce/core/api/RedisServerCommands.java | 11 +++++++-- .../KotlinCompilationUnitFactory.java | 6 +++-- .../ServerCommandIntegrationTests.java | 12 +++------- 20 files changed, 113 insertions(+), 58 deletions(-) diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index c002109198..49d94a9087 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -708,7 +708,7 @@ public RedisFuture flushall(FlushMode flushMode) { @Override public RedisFuture flushallAsync() { - return dispatch(commandBuilder.flushallAsync()); + return flushall(FlushMode.ASYNC); } @Override @@ -723,7 +723,7 @@ public RedisFuture flushdb(FlushMode flushMode) { @Override public RedisFuture flushdbAsync() { - return dispatch(commandBuilder.flushdbAsync()); + return flushdb(FlushMode.ASYNC); } @Override diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index 71621f5cad..d67c203d7a 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -766,7 +766,7 @@ public Mono flushall(FlushMode flushMode) { @Override public Mono flushallAsync() { - return createMono(commandBuilder::flushallAsync); + return flushall(FlushMode.ASYNC); } @Override @@ -781,7 +781,7 @@ public Mono flushdb(FlushMode flushMode) { @Override public Mono flushdbAsync() { - return createMono(commandBuilder::flushdbAsync); + return flushdb(FlushMode.ASYNC); } @Override diff --git a/src/main/java/io/lettuce/core/FlushMode.java b/src/main/java/io/lettuce/core/FlushMode.java index b47b01e1c7..27c8304391 100644 --- a/src/main/java/io/lettuce/core/FlushMode.java +++ b/src/main/java/io/lettuce/core/FlushMode.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2021 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. @@ -15,19 +15,36 @@ */ package io.lettuce.core; +import java.nio.charset.StandardCharsets; + +import io.lettuce.core.protocol.ProtocolKeyword; + /** * Enum object describing flushing mode. * * @author dengliming * @since 6.1 */ -public enum FlushMode { +public enum FlushMode implements ProtocolKeyword { + /** * flushes asynchronously */ SYNC, + /** * flushes synchronously */ - ASYNC + ASYNC; + + public final byte[] bytes; + + FlushMode() { + bytes = name().getBytes(StandardCharsets.US_ASCII); + } + + @Override + public byte[] getBytes() { + return bytes; + } } diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index bc712b8519..733080800f 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -20,7 +20,6 @@ import static io.lettuce.core.protocol.CommandType.*; import static io.lettuce.core.protocol.CommandType.COPY; import static io.lettuce.core.protocol.CommandType.SAVE; -import static io.lettuce.core.protocol.CommandType.SYNC; import java.nio.ByteBuffer; import java.util.Arrays; @@ -831,11 +830,7 @@ Command flushall() { Command flushall(FlushMode flushMode) { LettuceAssert.notNull(flushMode, "FlushMode " + MUST_NOT_BE_NULL); - return createCommand(FLUSHALL, new StatusOutput<>(codec), new CommandArgs<>(codec).add(flushMode.name())); - } - - Command flushallAsync() { - return createCommand(FLUSHALL, new StatusOutput<>(codec), new CommandArgs<>(codec).add(ASYNC)); + return createCommand(FLUSHALL, new StatusOutput<>(codec), new CommandArgs<>(codec).add(flushMode)); } Command flushdb() { @@ -845,11 +840,7 @@ Command flushdb() { Command flushdb(FlushMode flushMode) { LettuceAssert.notNull(flushMode, "FlushMode " + MUST_NOT_BE_NULL); - return createCommand(FLUSHDB, new StatusOutput<>(codec), new CommandArgs<>(codec).add(flushMode.name())); - } - - Command flushdbAsync() { - return createCommand(FLUSHDB, new StatusOutput<>(codec), new CommandArgs<>(codec).add(ASYNC)); + return createCommand(FLUSHDB, new StatusOutput<>(codec), new CommandArgs<>(codec).add(flushMode)); } Command geoadd(K key, double longitude, double latitude, V member, GeoAddArgs geoArgs) { diff --git a/src/main/java/io/lettuce/core/api/async/RedisScriptingAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisScriptingAsyncCommands.java index 779a57744f..159df0193d 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisScriptingAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisScriptingAsyncCommands.java @@ -122,8 +122,9 @@ public interface RedisScriptingAsyncCommands { RedisFuture scriptFlush(); /** - * Remove all the scripts from the script cache by the specified {@code flushMode}. + * Remove all the scripts from the script cache using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java index 3e4e83d613..a4a6f5a74e 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisServerAsyncCommands.java @@ -18,12 +18,13 @@ import java.util.Date; import java.util.List; import java.util.Map; + import io.lettuce.core.FlushMode; import io.lettuce.core.KillArgs; +import io.lettuce.core.RedisFuture; import io.lettuce.core.TrackingArgs; import io.lettuce.core.UnblockType; import io.lettuce.core.protocol.CommandType; -import io.lettuce.core.RedisFuture; /** * Asynchronous executed commands for Server Control. @@ -281,8 +282,9 @@ public interface RedisServerAsyncCommands { RedisFuture flushall(); /** - * Remove all keys from all databases by the specified {@code flushMode}. + * Remove all keys from all databases using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -292,7 +294,9 @@ public interface RedisServerAsyncCommands { * Remove all keys asynchronously from all databases. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushall(FlushMode)} instead. */ + @Deprecated RedisFuture flushallAsync(); /** @@ -303,8 +307,9 @@ public interface RedisServerAsyncCommands { RedisFuture flushdb(); /** - * Remove all keys from the current database by the specified {@code flushMode}. + * Remove all keys from the current database using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -314,7 +319,9 @@ public interface RedisServerAsyncCommands { * Remove all keys asynchronously from the current database. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushdb(FlushMode)} instead. */ + @Deprecated RedisFuture flushdbAsync(); /** diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisScriptingReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisScriptingReactiveCommands.java index ca74dd43a8..603642d244 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisScriptingReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisScriptingReactiveCommands.java @@ -15,9 +15,9 @@ */ package io.lettuce.core.api.reactive; -import io.lettuce.core.FlushMode; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import io.lettuce.core.FlushMode; import io.lettuce.core.ScriptOutputType; /** @@ -121,8 +121,9 @@ public interface RedisScriptingReactiveCommands { Mono scriptFlush(); /** - * Remove all the scripts from the script cache by the specified {@code flushMode}. + * Remove all the scripts from the script cache using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java index c130a8ed8d..2367d0a31e 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisServerReactiveCommands.java @@ -18,9 +18,9 @@ import java.util.Date; import java.util.Map; -import io.lettuce.core.FlushMode; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import io.lettuce.core.FlushMode; import io.lettuce.core.KillArgs; import io.lettuce.core.TrackingArgs; import io.lettuce.core.UnblockType; @@ -282,8 +282,9 @@ public interface RedisServerReactiveCommands { Mono flushall(); /** - * Remove all keys from all databases by the specified {@code flushMode}. + * Remove all keys from all databases using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -293,7 +294,9 @@ public interface RedisServerReactiveCommands { * Remove all keys asynchronously from all databases. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushall(FlushMode)} instead. */ + @Deprecated Mono flushallAsync(); /** @@ -304,8 +307,9 @@ public interface RedisServerReactiveCommands { Mono flushdb(); /** - * Remove all keys from the current database by the specified {@code flushMode}. + * Remove all keys from the current database using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -315,7 +319,9 @@ public interface RedisServerReactiveCommands { * Remove all keys asynchronously from the current database. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushdb(FlushMode)} instead. */ + @Deprecated Mono flushdbAsync(); /** diff --git a/src/main/java/io/lettuce/core/api/sync/RedisScriptingCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisScriptingCommands.java index ebc7a5f5ea..685de0d5dd 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisScriptingCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisScriptingCommands.java @@ -121,8 +121,9 @@ public interface RedisScriptingCommands { String scriptFlush(); /** - * Remove all the scripts from the script cache by the specified {@code flushMode}. + * Remove all the scripts from the script cache using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java index c5e3db6c36..1e172461a9 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java @@ -18,6 +18,7 @@ import java.util.Date; import java.util.List; import java.util.Map; + import io.lettuce.core.FlushMode; import io.lettuce.core.KillArgs; import io.lettuce.core.TrackingArgs; @@ -280,8 +281,9 @@ public interface RedisServerCommands { String flushall(); /** - * Remove all keys from all databases by the specified {@code flushMode}. + * Remove all keys from all databases using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -291,7 +293,9 @@ public interface RedisServerCommands { * Remove all keys asynchronously from all databases. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushall(FlushMode)} instead. */ + @Deprecated String flushallAsync(); /** @@ -302,8 +306,9 @@ public interface RedisServerCommands { String flushdb(); /** - * Remove all keys from the current database by the specified {@code flushMode}. + * Remove all keys from the current database using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -313,7 +318,9 @@ public interface RedisServerCommands { * Remove all keys asynchronously from the current database. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushdb(FlushMode)} instead. */ + @Deprecated String flushdbAsync(); /** diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionScriptingAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionScriptingAsyncCommands.java index a857fe4298..990a8b1063 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionScriptingAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionScriptingAsyncCommands.java @@ -121,8 +121,9 @@ public interface NodeSelectionScriptingAsyncCommands { AsyncExecutions scriptFlush(); /** - * Remove all the scripts from the script cache by the specified {@code flushMode}. + * Remove all the scripts from the script cache using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java index f85fc3aec9..66db2120d0 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionServerAsyncCommands.java @@ -18,6 +18,7 @@ import java.util.Date; import java.util.List; import java.util.Map; + import io.lettuce.core.FlushMode; import io.lettuce.core.KillArgs; import io.lettuce.core.TrackingArgs; @@ -266,8 +267,9 @@ public interface NodeSelectionServerAsyncCommands { AsyncExecutions flushall(); /** - * Remove all keys from all databases by the specified {@code flushMode}. + * Remove all keys from all databases using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -277,7 +279,9 @@ public interface NodeSelectionServerAsyncCommands { * Remove all keys asynchronously from all databases. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushall(FlushMode)} instead. */ + @Deprecated AsyncExecutions flushallAsync(); /** @@ -288,8 +292,9 @@ public interface NodeSelectionServerAsyncCommands { AsyncExecutions flushdb(); /** - * Remove all keys from the current database by the specified {@code flushMode}. + * Remove all keys from the current database using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -299,7 +304,9 @@ public interface NodeSelectionServerAsyncCommands { * Remove all keys asynchronously from the current database. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushdb(FlushMode)} instead. */ + @Deprecated AsyncExecutions flushdbAsync(); /** diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionScriptingCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionScriptingCommands.java index 99256fd880..95c0de2b9a 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionScriptingCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionScriptingCommands.java @@ -121,8 +121,9 @@ public interface NodeSelectionScriptingCommands { Executions scriptFlush(); /** - * Remove all the scripts from the script cache by the specified {@code flushMode}. + * Remove all the scripts from the script cache using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java index a4acd76bd5..47daeb70a8 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionServerCommands.java @@ -18,6 +18,7 @@ import java.util.Date; import java.util.List; import java.util.Map; + import io.lettuce.core.FlushMode; import io.lettuce.core.KillArgs; import io.lettuce.core.TrackingArgs; @@ -266,8 +267,9 @@ public interface NodeSelectionServerCommands { Executions flushall(); /** - * Remove all keys from all databases by the specified {@code flushMode}. + * Remove all keys from all databases using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -277,7 +279,9 @@ public interface NodeSelectionServerCommands { * Remove all keys asynchronously from all databases. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushall(FlushMode)} instead. */ + @Deprecated Executions flushallAsync(); /** @@ -288,8 +292,9 @@ public interface NodeSelectionServerCommands { Executions flushdb(); /** - * Remove all keys from the current database by the specified {@code flushMode}. + * Remove all keys from the current database using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -299,7 +304,9 @@ public interface NodeSelectionServerCommands { * Remove all keys asynchronously from the current database. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushdb(FlushMode)} instead. */ + @Deprecated Executions flushdbAsync(); /** diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingCoroutinesCommands.kt index b6ee31664b..0202857bf2 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisScriptingCoroutinesCommands.kt @@ -122,8 +122,9 @@ interface RedisScriptingCoroutinesCommands { suspend fun scriptFlush(): String? /** - * Remove all the scripts from the script cache by the specified `flushMode`. + * Remove all the scripts from the script cache using the specified [FlushMode]. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt index 389be57f2e..3ea01cc1a7 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisServerCoroutinesCommands.kt @@ -16,11 +16,7 @@ package io.lettuce.core.api.coroutines -import io.lettuce.core.ExperimentalLettuceCoroutinesApi -import io.lettuce.core.FlushMode -import io.lettuce.core.KillArgs -import io.lettuce.core.TrackingArgs -import io.lettuce.core.UnblockType +import io.lettuce.core.* import io.lettuce.core.protocol.CommandType import java.util.* @@ -281,8 +277,9 @@ interface RedisServerCoroutinesCommands { suspend fun flushall(): String? /** - * Remove all keys from all databases by the specified `flushMode`. + * Remove all keys from all databases using the specified [FlushMode]. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -292,7 +289,9 @@ interface RedisServerCoroutinesCommands { * Remove all keys asynchronously from all databases. * * @return String simple-string-reply. + * @deprecated since 6.1, use [flushall(FlushMode)] instead. */ + @Deprecated("since 6.1, use [flushall(FlushMode)] instead") suspend fun flushallAsync(): String? /** @@ -303,8 +302,9 @@ interface RedisServerCoroutinesCommands { suspend fun flushdb(): String? /** - * Remove all keys from the current database by the specified `flushMode`. + * Remove all keys from the current database using the specified [FlushMode]. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -314,7 +314,9 @@ interface RedisServerCoroutinesCommands { * Remove all keys asynchronously from the current database. * * @return String simple-string-reply. + * @deprecated since 6.1, use [flushdb(FlushMode)] instead. */ + @Deprecated("since 6.1, use [flushdb(FlushMode)] instead.") suspend fun flushdbAsync(): String? /** diff --git a/src/main/templates/io/lettuce/core/api/RedisScriptingCommands.java b/src/main/templates/io/lettuce/core/api/RedisScriptingCommands.java index 6bd0ecfbd5..cd70acee9a 100644 --- a/src/main/templates/io/lettuce/core/api/RedisScriptingCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisScriptingCommands.java @@ -17,6 +17,7 @@ import java.util.List; +import io.lettuce.core.FlushMode; import io.lettuce.core.ScriptOutputType; /** @@ -119,8 +120,9 @@ public interface RedisScriptingCommands { String scriptFlush(); /** - * Remove all the scripts from the script cache by the specified {@code flushMode}. + * Remove all the scripts from the script cache using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ diff --git a/src/main/templates/io/lettuce/core/api/RedisServerCommands.java b/src/main/templates/io/lettuce/core/api/RedisServerCommands.java index 6b23478c97..8445d03854 100644 --- a/src/main/templates/io/lettuce/core/api/RedisServerCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisServerCommands.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Map; +import io.lettuce.core.FlushMode; import io.lettuce.core.KillArgs; import io.lettuce.core.TrackingArgs; import io.lettuce.core.UnblockType; @@ -279,8 +280,9 @@ public interface RedisServerCommands { String flushall(); /** - * Remove all keys from all databases by the specified {@code flushMode}. + * Remove all keys from all databases using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -290,7 +292,9 @@ public interface RedisServerCommands { * Remove all keys asynchronously from all databases. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushall(FlushMode)} instead. */ + @Deprecated String flushallAsync(); /** @@ -301,8 +305,9 @@ public interface RedisServerCommands { String flushdb(); /** - * Remove all keys from the current database by the specified {@code flushMode}. + * Remove all keys from the current database using the specified {@link FlushMode}. * + * @param flushMode the flush mode (sync/asnync). * @return String simple-string-reply. * @since 6.1 */ @@ -312,7 +317,9 @@ public interface RedisServerCommands { * Remove all keys asynchronously from the current database. * * @return String simple-string-reply. + * @deprecated since 6.1, use {@link #flushdb(FlushMode)} instead. */ + @Deprecated String flushdbAsync(); /** diff --git a/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java b/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java index 1f38a37917..89e9704d1b 100644 --- a/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java +++ b/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java @@ -60,6 +60,8 @@ class KotlinCompilationUnitFactory { private static final Set NON_SUSPENDABLE_METHODS = LettuceSets.unmodifiableSet("isOpen", "flushCommands", "setAutoFlushCommands"); private static final Set SKIP_METHODS = LettuceSets.unmodifiableSet("BaseRedisCommands.reset", "getStatefulConnection"); + private static final Set KEEP_DEPRECATED_METHODS = LettuceSets.unmodifiableSet("flushallAsync", "flushdbAsync"); + private static final Set FLOW_METHODS = LettuceSets.unmodifiableSet("aclList", "aclLog", "dispatch", "geohash", "georadius", "georadiusbymember", "geosearch", "hgetall", "hkeys", "hmget", "hvals", "keys", "mget", "sdiff", "sinter", "smembers", "smismember", "sort", "srandmember", "sunion", @@ -169,9 +171,9 @@ private class MethodVisitor extends VoidVisitorAdapter { public void visit(MethodDeclaration method, Object arg) { // Skip deprecated and StreamingChannel methods - if (method.isAnnotationPresent(Deprecated.class) + if (!contains(KEEP_DEPRECATED_METHODS, method) && (method.isAnnotationPresent(Deprecated.class) || contains(SKIP_METHODS, method) - || method.getParameters().stream().anyMatch(p -> p.getType().asString().contains("StreamingChannel"))) { + || method.getParameters().stream().anyMatch(p -> p.getType().asString().contains("StreamingChannel")))) { return; } result diff --git a/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java index 7ff837fbbf..845b85abad 100644 --- a/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java @@ -27,13 +27,13 @@ import javax.inject.Inject; -import io.lettuce.core.FlushMode; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.extension.ExtendWith; +import io.lettuce.core.FlushMode; import io.lettuce.core.KeyValue; import io.lettuce.core.KillArgs; import io.lettuce.core.RedisClient; @@ -53,7 +53,6 @@ import io.lettuce.test.LettuceExtension; import io.lettuce.test.Wait; import io.lettuce.test.condition.EnabledOnCommand; -import io.lettuce.test.condition.RedisConditions; import io.lettuce.test.settings.TestSettings; /** @@ -393,10 +392,8 @@ void flushall() { } @Test + @EnabledOnCommand("MEMORY") // Redis 4.0 void flushallAsync() { - - assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("3.4")); - redis.set(key, value); assertThat(redis.flushallAsync()).isEqualTo("OK"); assertThat(redis.get(key)).isNull(); @@ -405,7 +402,6 @@ void flushallAsync() { @Test @EnabledOnCommand("XAUTOCLAIM") // Redis 6.2 void flushallSync() { - redis.set(key, value); assertThat(redis.flushall(FlushMode.SYNC)).isEqualTo("OK"); assertThat(redis.get(key)).isNull(); @@ -419,10 +415,8 @@ void flushdb() { } @Test + @EnabledOnCommand("MEMORY") // Redis 4.0 void flushdbAsync() { - - assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("3.4")); - redis.set(key, value); redis.select(1); redis.set(key, value + "X");