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

Add support for FT.DROPINDEX #2722 #3163

Closed
Closed
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
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ on:
branches:
- main
- '[0-9].*'
- 'feature/*'
pull_request:
branches:
- main
- '[0-9].*'
- 'feature/*'
schedule:
- cron: '0 1 * * *' # nightly build
workflow_dispatch:
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import io.lettuce.core.protocol.CommandType;
import io.lettuce.core.protocol.ProtocolKeyword;
import io.lettuce.core.protocol.RedisCommand;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;
import reactor.core.publisher.Mono;

import java.time.Duration;
Expand Down Expand Up @@ -79,14 +81,17 @@ public abstract class AbstractRedisAsyncCommands<K, V> implements RedisAclAsyncC
RedisKeyAsyncCommands<K, V>, RedisStringAsyncCommands<K, V>, RedisListAsyncCommands<K, V>, RedisSetAsyncCommands<K, V>,
RedisSortedSetAsyncCommands<K, V>, RedisScriptingAsyncCommands<K, V>, RedisServerAsyncCommands<K, V>,
RedisHLLAsyncCommands<K, V>, BaseRedisAsyncCommands<K, V>, RedisTransactionalAsyncCommands<K, V>,
RedisGeoAsyncCommands<K, V>, RedisClusterAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V> {
RedisGeoAsyncCommands<K, V>, RedisClusterAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V>,
RediSearchAsyncCommands<K, V> {

private final StatefulConnection<K, V> connection;

private final RedisCommandBuilder<K, V> commandBuilder;

private final RedisJsonCommandBuilder<K, V> jsonCommandBuilder;

private final RediSearchCommandBuilder<K, V> searchCommandBuilder;

private final Mono<JsonParser> parser;

/**
Expand All @@ -101,6 +106,7 @@ public AbstractRedisAsyncCommands(StatefulConnection<K, V> connection, RedisCode
this.connection = connection;
this.commandBuilder = new RedisCommandBuilder<>(codec);
this.jsonCommandBuilder = new RedisJsonCommandBuilder<>(codec, parser);
this.searchCommandBuilder = new RediSearchCommandBuilder<>(codec);
}

/**
Expand Down Expand Up @@ -1478,6 +1484,16 @@ public boolean isOpen() {
return connection.isOpen();
}

@Override
public RedisFuture<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields) {
return dispatch(searchCommandBuilder.ftCreate(index, options, fields));
}

@Override
public RedisFuture<String> ftDropindex(K index, boolean deleteDocumentKeys) {
return dispatch(searchCommandBuilder.ftDropindex(index, deleteDocumentKeys));
}

@Override
public RedisFuture<List<Long>> jsonArrappend(K key, JsonPath jsonPath, JsonValue... values) {
return dispatch(jsonCommandBuilder.jsonArrappend(key, jsonPath, values));
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import io.lettuce.core.protocol.RedisCommand;
import io.lettuce.core.protocol.TracedCommand;
import io.lettuce.core.resource.ClientResources;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;
import io.lettuce.core.tracing.TraceContext;
import io.lettuce.core.tracing.TraceContextProvider;
import io.lettuce.core.tracing.Tracing;
Expand Down Expand Up @@ -84,19 +86,21 @@
* @author Tihomir Mateev
* @since 4.0
*/
public abstract class AbstractRedisReactiveCommands<K, V>
implements RedisAclReactiveCommands<K, V>, RedisHashReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>,
RedisStringReactiveCommands<K, V>, RedisListReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>,
RedisSortedSetReactiveCommands<K, V>, RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>,
RedisHLLReactiveCommands<K, V>, BaseRedisReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>,
RedisGeoReactiveCommands<K, V>, RedisClusterReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V> {
public abstract class AbstractRedisReactiveCommands<K, V> implements RedisAclReactiveCommands<K, V>,
RedisHashReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>, RedisStringReactiveCommands<K, V>,
RedisListReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>, RedisSortedSetReactiveCommands<K, V>,
RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>, RedisHLLReactiveCommands<K, V>,
BaseRedisReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>,
RedisClusterReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V>, RediSearchReactiveCommands<K, V> {

private final StatefulConnection<K, V> connection;

private final RedisCommandBuilder<K, V> commandBuilder;

private final RedisJsonCommandBuilder<K, V> jsonCommandBuilder;

private final RediSearchCommandBuilder<K, V> searchCommandBuilder;

private final Mono<JsonParser> parser;

private final ClientResources clientResources;
Expand All @@ -117,6 +121,7 @@ public AbstractRedisReactiveCommands(StatefulConnection<K, V> connection, RedisC
this.parser = parser;
this.commandBuilder = new RedisCommandBuilder<>(codec);
this.jsonCommandBuilder = new RedisJsonCommandBuilder<>(codec, parser);
this.searchCommandBuilder = new RediSearchCommandBuilder<>(codec);
this.clientResources = connection.getResources();
this.tracingEnabled = clientResources.tracing().isEnabled();
}
Expand Down Expand Up @@ -1543,6 +1548,16 @@ public boolean isOpen() {
return connection.isOpen();
}

@Override
public Mono<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields) {
return createMono(() -> searchCommandBuilder.ftCreate(index, options, fields));
}

@Override
public Mono<String> ftDropindex(K index, boolean deleteDocumentKeys) {
return createMono(() -> searchCommandBuilder.ftDropindex(index, deleteDocumentKeys));
}

@Override
public Flux<Long> jsonArrappend(K key, JsonPath jsonPath, JsonValue... values) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonArrappend(key, jsonPath, values));
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/io/lettuce/core/RediSearchCommandBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core;

import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.output.StatusOutput;
import io.lettuce.core.protocol.BaseRedisCommandBuilder;
import io.lettuce.core.protocol.Command;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandKeyword;
import io.lettuce.core.protocol.RedisCommand;
import io.lettuce.core.search.arguments.CreateArgs;
import io.lettuce.core.search.Field;

import java.util.List;

import static io.lettuce.core.protocol.CommandType.*;

/**
* Command builder for RediSearch commands.
*
* @param <K> Key type.
* @param <V> Value type.
* @since 6.6
*/
class RediSearchCommandBuilder<K, V> extends BaseRedisCommandBuilder<K, V> {

RediSearchCommandBuilder(RedisCodec<K, V> codec) {
super(codec);
}

/**
* Create a new index with the given name, index options and fields.
*
* @param index the index name
* @param createArgs the index options
* @param fields the fields
* @return the result of the create command
*/
public Command<K, V, String> ftCreate(K index, CreateArgs<K, V> createArgs, List<Field<K>> fields) {
notNullKey(index);
notEmpty(fields.toArray());

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(index);

if (createArgs != null) {
createArgs.build(args);
}

args.add(CommandKeyword.SCHEMA);

for (Field<K> field : fields) {
field.build(args);
}

return createCommand(FT_CREATE, new StatusOutput<>(codec), args);

}

public Command<K, V, String> ftDropindex(K index, boolean deleteDocumentKeys) {
notNullKey(index);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(index);

if (deleteDocumentKeys) {
args.add(CommandKeyword.DD);
}

return createCommand(FT_DROPINDEX, new StatusOutput<>(codec), args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.api.async;

import java.util.List;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;

/**
* Asynchronous executed commands for RediSearch functionality
*
* @param <K> Key type.
* @param <V> Value type.
* @author Tihomir Mateev
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
* @since 6.6
* @generated by io.lettuce.apigenerator.CreateAsyncApi
*/
public interface RediSearchAsyncCommands<K, V> {

/**
* Create a new index with the given name, index options, and fields.
*
* @param index the index name, as a key
* @param options the index {@link CreateArgs}
* @param fields the {@link Field}s of the index
* @return the result of the create command
* @since 6.6
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
*/
RedisFuture<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);

/**
* Drop an index.
* <p/>
* By default, <a href="https://redis.io/docs/latest/commands/ft.dropindex/">FT.DROPINDEX</a> does not delete the documents
* associated with the index. Adding the <code>deleteDocuments</code> option deletes the documents as well. If an index
* creation is still running (<a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a> is running
* asynchronously), only the document hashes that have already been indexed are deleted. The document hashes left to be
* indexed remain in the database.
*
* @param index the index name, as a key
* @param deleteDocuments if true, delete the documents as well
* @return the result of the drop command
* @since 6.6
* @see <a href="https://redis.io/docs/latest/commands/ft.dropindex/">FT.DROPINDEX</a>
*/
RedisFuture<String> ftDropindex(K index, boolean deleteDocuments);

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface RedisAsyncCommands<K, V> extends BaseRedisAsyncCommands<K, V>,
RedisHashAsyncCommands<K, V>, RedisHLLAsyncCommands<K, V>, RedisKeyAsyncCommands<K, V>, RedisListAsyncCommands<K, V>,
RedisScriptingAsyncCommands<K, V>, RedisServerAsyncCommands<K, V>, RedisSetAsyncCommands<K, V>,
RedisSortedSetAsyncCommands<K, V>, RedisStreamAsyncCommands<K, V>, RedisStringAsyncCommands<K, V>,
RedisTransactionalAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V> {
RedisTransactionalAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V>, RediSearchAsyncCommands<K, V> {

/**
* Authenticate to the server.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.api.reactive;

import java.util.List;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;
import reactor.core.publisher.Mono;

/**
* Reactive executed commands for RediSearch functionality
*
* @param <K> Key type.
* @param <V> Value type.
* @author Tihomir Mateev
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
* @since 6.6
* @generated by io.lettuce.apigenerator.CreateReactiveApi
*/
public interface RediSearchReactiveCommands<K, V> {

/**
* Create a new index with the given name, index options, and fields.
*
* @param index the index name, as a key
* @param options the index {@link CreateArgs}
* @param fields the {@link Field}s of the index
* @return the result of the create command
* @since 6.6
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
*/
Mono<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);

/**
* Drop an index.
* <p/>
* By default, <a href="https://redis.io/docs/latest/commands/ft.dropindex/">FT.DROPINDEX</a> does not delete the documents
* associated with the index. Adding the <code>deleteDocuments</code> option deletes the documents as well. If an index
* creation is still running (<a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a> is running
* asynchronously), only the document hashes that have already been indexed are deleted. The document hashes left to be
* indexed remain in the database.
*
* @param index the index name, as a key
* @param deleteDocuments if true, delete the documents as well
* @return the result of the drop command
* @since 6.6
* @see <a href="https://redis.io/docs/latest/commands/ft.dropindex/">FT.DROPINDEX</a>
*/
Mono<String> ftDropindex(K index, boolean deleteDocuments);

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
* @author Mark Paluch
* @since 5.0
*/
public interface RedisReactiveCommands<K, V> extends BaseRedisReactiveCommands<K, V>, RedisAclReactiveCommands<K, V>,
RedisClusterReactiveCommands<K, V>, RedisFunctionReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>,
RedisHashReactiveCommands<K, V>, RedisHLLReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>,
RedisListReactiveCommands<K, V>, RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>,
RedisSetReactiveCommands<K, V>, RedisSortedSetReactiveCommands<K, V>, RedisStreamReactiveCommands<K, V>,
RedisStringReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V> {
public interface RedisReactiveCommands<K, V>
extends BaseRedisReactiveCommands<K, V>, RedisAclReactiveCommands<K, V>, RedisClusterReactiveCommands<K, V>,
RedisFunctionReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>, RedisHashReactiveCommands<K, V>,
RedisHLLReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>, RedisListReactiveCommands<K, V>,
RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>,
RedisSortedSetReactiveCommands<K, V>, RedisStreamReactiveCommands<K, V>, RedisStringReactiveCommands<K, V>,
RedisTransactionalReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V>, RediSearchReactiveCommands<K, V> {

/**
* Authenticate to the server.
Expand Down
Loading
Loading