Skip to content

Commit

Permalink
Add FlushMode to FLUSHALL and FLUSHDB, and to SCRIPT FLUSH #1608
Browse files Browse the repository at this point in the history
Original pull request: #1646.
  • Loading branch information
dengliming authored and mp911de committed Mar 9, 2021
1 parent 1241b10 commit 4f590cc
Show file tree
Hide file tree
Showing 23 changed files with 326 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,11 @@ public RedisFuture<String> flushall() {
return dispatch(commandBuilder.flushall());
}

@Override
public RedisFuture<String> flushall(FlushMode flushMode) {
return dispatch(commandBuilder.flushall(flushMode));
}

@Override
public RedisFuture<String> flushallAsync() {
return dispatch(commandBuilder.flushallAsync());
Expand All @@ -711,6 +716,11 @@ public RedisFuture<String> flushdb() {
return dispatch(commandBuilder.flushdb());
}

@Override
public RedisFuture<String> flushdb(FlushMode flushMode) {
return dispatch(commandBuilder.flushdb(flushMode));
}

@Override
public RedisFuture<String> flushdbAsync() {
return dispatch(commandBuilder.flushdbAsync());
Expand Down Expand Up @@ -1446,6 +1456,11 @@ public RedisFuture<String> scriptFlush() {
return dispatch(commandBuilder.scriptFlush());
}

@Override
public RedisFuture<String> scriptFlush(FlushMode flushMode) {
return dispatch(commandBuilder.scriptFlush(flushMode));
}

@Override
public RedisFuture<String> scriptKill() {
return dispatch(commandBuilder.scriptKill());
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,11 @@ public Mono<String> flushall() {
return createMono(commandBuilder::flushall);
}

@Override
public Mono<String> flushall(FlushMode flushMode) {
return createMono(() -> commandBuilder.flushall(flushMode));
}

@Override
public Mono<String> flushallAsync() {
return createMono(commandBuilder::flushallAsync);
Expand All @@ -769,6 +774,11 @@ public Mono<String> flushdb() {
return createMono(commandBuilder::flushdb);
}

@Override
public Mono<String> flushdb(FlushMode flushMode) {
return createMono(() -> commandBuilder.flushdb(flushMode));
}

@Override
public Mono<String> flushdbAsync() {
return createMono(commandBuilder::flushdbAsync);
Expand Down Expand Up @@ -1521,6 +1531,11 @@ public Mono<String> scriptFlush() {
return createMono(commandBuilder::scriptFlush);
}

@Override
public Mono<String> scriptFlush(FlushMode flushMode) {
return createMono(() -> commandBuilder.scriptFlush(flushMode));
}

@Override
public Mono<String> scriptKill() {
return createMono(commandBuilder::scriptKill);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/io/lettuce/core/FlushMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2018-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.
* 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;

/**
* Enum object describing flushing mode.
*
* @author dengliming
* @since 6.1
*/
public enum FlushMode {
/**
* flushes asynchronously
*/
SYNC,
/**
* flushes synchronously
*/
ASYNC
}
20 changes: 20 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -827,6 +828,12 @@ Command<K, V, String> flushall() {
return createCommand(FLUSHALL, new StatusOutput<>(codec));
}

Command<K, V, String> flushall(FlushMode flushMode) {
LettuceAssert.notNull(flushMode, "FlushMode " + MUST_NOT_BE_NULL);

return createCommand(FLUSHALL, new StatusOutput<>(codec), new CommandArgs<>(codec).add(flushMode.name()));
}

Command<K, V, String> flushallAsync() {
return createCommand(FLUSHALL, new StatusOutput<>(codec), new CommandArgs<>(codec).add(ASYNC));
}
Expand All @@ -835,6 +842,12 @@ Command<K, V, String> flushdb() {
return createCommand(FLUSHDB, new StatusOutput<>(codec));
}

Command<K, V, String> flushdb(FlushMode flushMode) {
LettuceAssert.notNull(flushMode, "FlushMode " + MUST_NOT_BE_NULL);

return createCommand(FLUSHDB, new StatusOutput<>(codec), new CommandArgs<>(codec).add(flushMode.name()));
}

Command<K, V, String> flushdbAsync() {
return createCommand(FLUSHDB, new StatusOutput<>(codec), new CommandArgs<>(codec).add(ASYNC));
}
Expand Down Expand Up @@ -2022,6 +2035,13 @@ Command<K, V, String> scriptFlush() {
return createCommand(SCRIPT, new StatusOutput<>(codec), args);
}

Command<K, V, String> scriptFlush(FlushMode flushMode) {
LettuceAssert.notNull(flushMode, "FlushMode " + MUST_NOT_BE_NULL);

CommandArgs<K, V> args = new CommandArgs<>(codec).add(FLUSH).add(flushMode.name());
return createCommand(SCRIPT, new StatusOutput<>(codec), args);
}

Command<K, V, String> scriptKill() {
CommandArgs<K, V> args = new CommandArgs<>(codec).add(KILL);
return createCommand(SCRIPT, new StatusOutput<>(codec), args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.List;

import io.lettuce.core.FlushMode;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.ScriptOutputType;

Expand Down Expand Up @@ -120,6 +121,14 @@ public interface RedisScriptingAsyncCommands<K, V> {
*/
RedisFuture<String> scriptFlush();

/**
* Remove all the scripts from the script cache by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
RedisFuture<String> scriptFlush(FlushMode flushMode);

/**
* Kill the script currently in execution.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
import io.lettuce.core.UnblockType;
Expand Down Expand Up @@ -279,6 +280,14 @@ public interface RedisServerAsyncCommands<K, V> {
*/
RedisFuture<String> flushall();

/**
* Remove all keys from all databases by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
RedisFuture<String> flushall(FlushMode flushMode);

/**
* Remove all keys asynchronously from all databases.
*
Expand All @@ -293,6 +302,14 @@ public interface RedisServerAsyncCommands<K, V> {
*/
RedisFuture<String> flushdb();

/**
* Remove all keys from the current database by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
RedisFuture<String> flushdb(FlushMode flushMode);

/**
* Remove all keys asynchronously from the current database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
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.ScriptOutputType;
Expand Down Expand Up @@ -119,6 +120,14 @@ public interface RedisScriptingReactiveCommands<K, V> {
*/
Mono<String> scriptFlush();

/**
* Remove all the scripts from the script cache by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
Mono<String> scriptFlush(FlushMode flushMode);

/**
* Kill the script currently in execution.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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.KillArgs;
Expand Down Expand Up @@ -280,6 +281,14 @@ public interface RedisServerReactiveCommands<K, V> {
*/
Mono<String> flushall();

/**
* Remove all keys from all databases by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
Mono<String> flushall(FlushMode flushMode);

/**
* Remove all keys asynchronously from all databases.
*
Expand All @@ -294,6 +303,14 @@ public interface RedisServerReactiveCommands<K, V> {
*/
Mono<String> flushdb();

/**
* Remove all keys from the current database by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
Mono<String> flushdb(FlushMode flushMode);

/**
* Remove all keys asynchronously from the current database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.List;

import io.lettuce.core.FlushMode;
import io.lettuce.core.ScriptOutputType;

/**
Expand Down Expand Up @@ -119,6 +120,14 @@ public interface RedisScriptingCommands<K, V> {
*/
String scriptFlush();

/**
* Remove all the scripts from the script cache by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
String scriptFlush(FlushMode flushMode);

/**
* Kill the script currently in execution.
*
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/io/lettuce/core/api/sync/RedisServerCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
import io.lettuce.core.UnblockType;
Expand Down Expand Up @@ -278,6 +279,14 @@ public interface RedisServerCommands<K, V> {
*/
String flushall();

/**
* Remove all keys from all databases by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
String flushall(FlushMode flushMode);

/**
* Remove all keys asynchronously from all databases.
*
Expand All @@ -292,6 +301,14 @@ public interface RedisServerCommands<K, V> {
*/
String flushdb();

/**
* Remove all keys from the current database by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
String flushdb(FlushMode flushMode);

/**
* Remove all keys asynchronously from the current database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.List;

import io.lettuce.core.FlushMode;
import io.lettuce.core.ScriptOutputType;

/**
Expand Down Expand Up @@ -119,6 +120,14 @@ public interface NodeSelectionScriptingAsyncCommands<K, V> {
*/
AsyncExecutions<String> scriptFlush();

/**
* Remove all the scripts from the script cache by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
AsyncExecutions<String> scriptFlush(FlushMode flushMode);

/**
* Kill the script currently in execution.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
import io.lettuce.core.UnblockType;
Expand Down Expand Up @@ -264,6 +265,14 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
*/
AsyncExecutions<String> flushall();

/**
* Remove all keys from all databases by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
AsyncExecutions<String> flushall(FlushMode flushMode);

/**
* Remove all keys asynchronously from all databases.
*
Expand All @@ -278,6 +287,14 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
*/
AsyncExecutions<String> flushdb();

/**
* Remove all keys from the current database by the specified {@code flushMode}.
*
* @return String simple-string-reply.
* @since 6.1
*/
AsyncExecutions<String> flushdb(FlushMode flushMode);

/**
* Remove all keys asynchronously from the current database.
*
Expand Down
Loading

0 comments on commit 4f590cc

Please sign in to comment.