Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: Add FUNCTION FLUSH command. #1533

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions glide-core/src/protobuf/redis_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ enum RequestType {
FunctionLoad = 150;
FunctionList = 151;
FunctionDelete = 152;
FunctionFlush = 153;
LMPop = 155;
ExpireTime = 156;
PExpireTime = 157;
Expand Down
3 changes: 3 additions & 0 deletions glide-core/src/request_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub enum RequestType {
FunctionLoad = 150,
FunctionList = 151,
FunctionDelete = 152,
FunctionFlush = 153,
LMPop = 155,
ExpireTime = 156,
PExpireTime = 157,
Expand Down Expand Up @@ -343,6 +344,7 @@ impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
ProtobufRequestType::FunctionLoad => RequestType::FunctionLoad,
ProtobufRequestType::FunctionList => RequestType::FunctionList,
ProtobufRequestType::FunctionDelete => RequestType::FunctionDelete,
ProtobufRequestType::FunctionFlush => RequestType::FunctionFlush,
ProtobufRequestType::BitPos => RequestType::BitPos,
ProtobufRequestType::BitOp => RequestType::BitOp,
ProtobufRequestType::HStrlen => RequestType::HStrlen,
Expand Down Expand Up @@ -521,6 +523,7 @@ impl RequestType {
RequestType::FunctionLoad => Some(get_two_word_command("FUNCTION", "LOAD")),
RequestType::FunctionList => Some(get_two_word_command("FUNCTION", "LIST")),
RequestType::FunctionDelete => Some(get_two_word_command("FUNCTION", "DELETE")),
RequestType::FunctionFlush => Some(get_two_word_command("FUNCTION", "FLUSH")),
RequestType::BitPos => Some(cmd("BITPOS")),
RequestType::BitOp => Some(cmd("BITOP")),
RequestType::HStrlen => Some(cmd("HSTRLEN")),
Expand Down
13 changes: 13 additions & 0 deletions java/client/src/main/java/glide/api/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.Echo;
import static redis_request.RedisRequestOuterClass.RequestType.FlushAll;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionDelete;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionFlush;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionList;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionLoad;
import static redis_request.RedisRequestOuterClass.RequestType.Info;
Expand Down Expand Up @@ -227,6 +228,18 @@ public CompletableFuture<Map<String, Object>[]> functionList(
response -> handleFunctionListResponse(handleArrayResponse(response)));
}

@Override
public CompletableFuture<String> functionFlush() {
return commandManager.submitNewCommand(
FunctionFlush, new String[0], this::handleStringResponse);
}

@Override
public CompletableFuture<String> functionFlush(@NonNull FlushMode mode) {
return commandManager.submitNewCommand(
FunctionFlush, new String[] {mode.toString()}, this::handleStringResponse);
}

@Override
public CompletableFuture<String> functionDelete(@NonNull String libName) {
return commandManager.submitNewCommand(
Expand Down
25 changes: 25 additions & 0 deletions java/client/src/main/java/glide/api/RedisClusterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.Echo;
import static redis_request.RedisRequestOuterClass.RequestType.FlushAll;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionDelete;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionFlush;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionList;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionLoad;
import static redis_request.RedisRequestOuterClass.RequestType.Info;
Expand Down Expand Up @@ -496,6 +497,30 @@ public CompletableFuture<ClusterValue<Map<String, Object>[]>> functionList(
response -> handleFunctionListResponse(response, route));
}

@Override
public CompletableFuture<String> functionFlush() {
return commandManager.submitNewCommand(
FunctionFlush, new String[0], this::handleStringResponse);
}

@Override
public CompletableFuture<String> functionFlush(@NonNull FlushMode mode) {
return commandManager.submitNewCommand(
FunctionFlush, new String[] {mode.toString()}, this::handleStringResponse);
}

@Override
public CompletableFuture<String> functionFlush(@NonNull Route route) {
return commandManager.submitNewCommand(
FunctionFlush, new String[0], route, this::handleStringResponse);
}

@Override
public CompletableFuture<String> functionFlush(@NonNull FlushMode mode, @NonNull Route route) {
return commandManager.submitNewCommand(
FunctionFlush, new String[] {mode.toString()}, route, this::handleStringResponse);
}

@Override
public CompletableFuture<String> functionDelete(@NonNull String libName) {
return commandManager.submitNewCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package glide.api.commands;

import glide.api.models.ClusterValue;
import glide.api.models.commands.FlushMode;
import glide.api.models.configuration.RequestRoutingConfiguration.Route;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -168,6 +169,72 @@ CompletableFuture<ClusterValue<Map<String, Object>[]>> functionList(
CompletableFuture<ClusterValue<Map<String, Object>[]>> functionList(
String libNamePattern, boolean withCode, Route route);

/**
* Deletes all function libraries.<br>
* The command will be routed to all primary nodes.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/docs/latest/commands/function-flush/">redis.io</a> for details.
* @return <code>OK</code>.
* @example
* <pre>{@code
* String response = client.functionFlush().get();
* assert response.equals("OK");
* }</pre>
*/
CompletableFuture<String> functionFlush();

/**
* Deletes all function libraries.<br>
* The command will be routed to all primary nodes.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/docs/latest/commands/function-flush/">redis.io</a> for details.
* @param mode The flushing mode, could be either {@link FlushMode#SYNC} or {@link
* FlushMode#ASYNC}.
* @return <code>OK</code>.
* @example
* <pre>{@code
* String response = client.functionFlush(SYNC).get();
* assert response.equals("OK");
* }</pre>
*/
CompletableFuture<String> functionFlush(FlushMode mode);

/**
* Deletes all function libraries.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/docs/latest/commands/function-flush/">redis.io</a> for details.
* @param route Specifies the routing configuration for the command. The client will route the
* command to the nodes defined by <code>route</code>.
* @return <code>OK</code>.
* @example
* <pre>{@code
* String response = client.functionFlush(RANDOM).get();
* assert response.equals("OK");
* }</pre>
*/
CompletableFuture<String> functionFlush(Route route);

/**
* Deletes all function libraries.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/docs/latest/commands/function-flush/">redis.io</a> for details.
* @param mode The flushing mode, could be either {@link FlushMode#SYNC} or {@link
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
* FlushMode#ASYNC}.
* @param route Specifies the routing configuration for the command. The client will route the
* command to the nodes defined by <code>route</code>.
* @return <code>OK</code>.
* @example
* <pre>{@code
* String response = client.functionFlush(SYNC, RANDOM).get();
* assert response.equals("OK");
* }</pre>
*/
CompletableFuture<String> functionFlush(FlushMode mode, Route route);

/**
* Deletes a library and all its functions.<br>
* The command will be routed to all primary nodes.
Expand All @@ -190,8 +257,6 @@ CompletableFuture<ClusterValue<Map<String, Object>[]>> functionList(
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/docs/latest/commands/function-delete/">redis.io</a> for details.
* @param libName The library name to delete.
* @param route Specifies the routing configuration for the command. The client will route the
* command to the nodes defined by <code>route</code>.
* @return <code>OK</code>.
* @example
* <pre>{@code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.commands;

import glide.api.models.commands.FlushMode;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -82,6 +83,36 @@ public interface ScriptingAndFunctionsCommands {
*/
CompletableFuture<Map<String, Object>[]> functionList(String libNamePattern, boolean withCode);

/**
* Deletes all function libraries.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/docs/latest/commands/function-flush/">redis.io</a> for details.
* @return <code>OK</code>.
* @example
* <pre>{@code
* String response = client.functionFlush().get();
* assert response.equals("OK");
* }</pre>
*/
CompletableFuture<String> functionFlush();

/**
* Deletes all function libraries.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/docs/latest/commands/function-flush/">redis.io</a> for details.
* @param mode The flushing mode, could be either {@link FlushMode#SYNC} or {@link
* FlushMode#ASYNC}.
* @return <code>OK</code>.
* @example
* <pre>{@code
* String response = client.functionFlush(SYNC).get();
* assert response.equals("OK");
* }</pre>
*/
CompletableFuture<String> functionFlush(FlushMode mode);

/**
* Deletes a library and all its functions.
*
Expand Down
27 changes: 27 additions & 0 deletions java/client/src/main/java/glide/api/models/BaseTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.ExpireTime;
import static redis_request.RedisRequestOuterClass.RequestType.FlushAll;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionDelete;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionFlush;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionList;
import static redis_request.RedisRequestOuterClass.RequestType.FunctionLoad;
import static redis_request.RedisRequestOuterClass.RequestType.GeoAdd;
Expand Down Expand Up @@ -4140,6 +4141,32 @@ public T bitfieldReadOnly(
return getThis();
}

/**
* Deletes all function libraries.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/docs/latest/commands/function-flush/">redis.io</a> for details.
* @return Command Response - <code>OK</code>.
*/
public T functionFlush() {
protobufTransaction.addCommands(buildCommand(FunctionFlush));
return getThis();
}

/**
* Deletes all function libraries.
*
* @since Redis 7.0 and above.
* @see <a href="https://redis.io/docs/latest/commands/function-flush/">redis.io</a> for details.
* @param mode The flushing mode, could be either {@link FlushMode#SYNC} or {@link
* FlushMode#ASYNC}.
* @return Command Response - <code>OK</code>.
*/
public T functionFlush(@NonNull FlushMode mode) {
protobufTransaction.addCommands(buildCommand(FunctionFlush, buildArgs(mode.toString())));
return getThis();
}

/**
* Deletes a library and all its functions.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@
import glide.api.RedisClient;
import glide.api.RedisClusterClient;
import glide.api.models.configuration.RequestRoutingConfiguration.Route;
import glide.api.models.configuration.RequestRoutingConfiguration.SingleNodeRoute;

// TODO add links to script flush
/**
* Defines flushing mode for <code>FLUSHALL</code> command implemented by {@link
* RedisClient#flushall(FlushMode)}, {@link RedisClusterClient#flushall(FlushMode)}, and {@link
* RedisClusterClient#flushall(FlushMode, Route)}.
* Defines flushing mode for:
*
* @see <a href="https://valkey.io/commands/flushall/">valkey.io</a>
* <ul>
* <li><code>FLUSHALL</code> command implemented by {@link RedisClient#flushall(FlushMode)},
* {@link RedisClusterClient#flushall(FlushMode)}, and {@link
* RedisClusterClient#flushall(FlushMode, SingleNodeRoute)}.
* <li><code>FUNCTION FLUSH</code> command implemented by {@link
* RedisClient#functionFlush(FlushMode)}, {@link RedisClusterClient#functionFlush(FlushMode)},
* and {@link RedisClusterClient#functionFlush(FlushMode, Route)}.
* </ul>
*
* @see <a href="https://valkey.io/commands/flushall/">valkey.io</a> and <a
* href="https://valkey.io/commands/function-flush/">valkey.io</a>
*/
public enum FlushMode {
/** Flushes the databases synchronously. */
/** Flushes synchronously. */
SYNC,
/** Flushes the databases asynchronously. */
/** Flushes asynchronously. */
ASYNC
}
Loading
Loading