Skip to content

Commit

Permalink
Polishing #1608
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mp911de committed Mar 9, 2021
1 parent 4f590cc commit 243d1cc
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ public RedisFuture<String> flushall(FlushMode flushMode) {

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

@Override
Expand All @@ -723,7 +723,7 @@ public RedisFuture<String> flushdb(FlushMode flushMode) {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ public Mono<String> flushall(FlushMode flushMode) {

@Override
public Mono<String> flushallAsync() {
return createMono(commandBuilder::flushallAsync);
return flushall(FlushMode.ASYNC);
}

@Override
Expand All @@ -781,7 +781,7 @@ public Mono<String> flushdb(FlushMode flushMode) {

@Override
public Mono<String> flushdbAsync() {
return createMono(commandBuilder::flushdbAsync);
return flushdb(FlushMode.ASYNC);
}

@Override
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/io/lettuce/core/FlushMode.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}
}
13 changes: 2 additions & 11 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -831,11 +830,7 @@ Command<K, V, String> flushall() {
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));
return createCommand(FLUSHALL, new StatusOutput<>(codec), new CommandArgs<>(codec).add(flushMode));
}

Command<K, V, String> flushdb() {
Expand All @@ -845,11 +840,7 @@ Command<K, V, String> flushdb() {
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));
return createCommand(FLUSHDB, new StatusOutput<>(codec), new CommandArgs<>(codec).add(flushMode));
}

Command<K, V, Long> geoadd(K key, double longitude, double latitude, V member, GeoAddArgs geoArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ public interface RedisScriptingAsyncCommands<K, V> {
RedisFuture<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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -281,8 +282,9 @@ public interface RedisServerAsyncCommands<K, V> {
RedisFuture<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
*/
Expand All @@ -292,7 +294,9 @@ public interface RedisServerAsyncCommands<K, V> {
* Remove all keys asynchronously from all databases.
*
* @return String simple-string-reply.
* @deprecated since 6.1, use {@link #flushall(FlushMode)} instead.
*/
@Deprecated
RedisFuture<String> flushallAsync();

/**
Expand All @@ -303,8 +307,9 @@ public interface RedisServerAsyncCommands<K, V> {
RedisFuture<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
*/
Expand All @@ -314,7 +319,9 @@ public interface RedisServerAsyncCommands<K, V> {
* Remove all keys asynchronously from the current database.
*
* @return String simple-string-reply.
* @deprecated since 6.1, use {@link #flushdb(FlushMode)} instead.
*/
@Deprecated
RedisFuture<String> flushdbAsync();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -121,8 +121,9 @@ public interface RedisScriptingReactiveCommands<K, V> {
Mono<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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -282,8 +282,9 @@ public interface RedisServerReactiveCommands<K, V> {
Mono<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
*/
Expand All @@ -293,7 +294,9 @@ public interface RedisServerReactiveCommands<K, V> {
* Remove all keys asynchronously from all databases.
*
* @return String simple-string-reply.
* @deprecated since 6.1, use {@link #flushall(FlushMode)} instead.
*/
@Deprecated
Mono<String> flushallAsync();

/**
Expand All @@ -304,8 +307,9 @@ public interface RedisServerReactiveCommands<K, V> {
Mono<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
*/
Expand All @@ -315,7 +319,9 @@ public interface RedisServerReactiveCommands<K, V> {
* Remove all keys asynchronously from the current database.
*
* @return String simple-string-reply.
* @deprecated since 6.1, use {@link #flushdb(FlushMode)} instead.
*/
@Deprecated
Mono<String> flushdbAsync();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ public interface RedisScriptingCommands<K, V> {
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
*/
Expand Down
11 changes: 9 additions & 2 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;
Expand Down Expand Up @@ -280,8 +281,9 @@ public interface RedisServerCommands<K, V> {
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
*/
Expand All @@ -291,7 +293,9 @@ public interface RedisServerCommands<K, V> {
* Remove all keys asynchronously from all databases.
*
* @return String simple-string-reply.
* @deprecated since 6.1, use {@link #flushall(FlushMode)} instead.
*/
@Deprecated
String flushallAsync();

/**
Expand All @@ -302,8 +306,9 @@ public interface RedisServerCommands<K, V> {
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
*/
Expand All @@ -313,7 +318,9 @@ public interface RedisServerCommands<K, V> {
* 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();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ public interface NodeSelectionScriptingAsyncCommands<K, V> {
AsyncExecutions<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
*/
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;
Expand Down Expand Up @@ -266,8 +267,9 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
AsyncExecutions<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
*/
Expand All @@ -277,7 +279,9 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
* Remove all keys asynchronously from all databases.
*
* @return String simple-string-reply.
* @deprecated since 6.1, use {@link #flushall(FlushMode)} instead.
*/
@Deprecated
AsyncExecutions<String> flushallAsync();

/**
Expand All @@ -288,8 +292,9 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
AsyncExecutions<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
*/
Expand All @@ -299,7 +304,9 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
* Remove all keys asynchronously from the current database.
*
* @return String simple-string-reply.
* @deprecated since 6.1, use {@link #flushdb(FlushMode)} instead.
*/
@Deprecated
AsyncExecutions<String> flushdbAsync();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ public interface NodeSelectionScriptingCommands<K, V> {
Executions<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
*/
Expand Down
Loading

0 comments on commit 243d1cc

Please sign in to comment.