Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury-Fridlyand committed Sep 25, 2024
1 parent e599742 commit 9e3ce53
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 0 deletions.
2 changes: 2 additions & 0 deletions glide-core/src/protobuf/command_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ enum RequestType {
ScriptFlush = 216;
ScriptKill = 217;
ScriptShow = 218;

FtCreate = 2000;
}

message Command {
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 @@ -227,6 +227,7 @@ pub enum RequestType {
ScriptFlush = 216,
ScriptKill = 217,
ScriptShow = 218,
FtCreate = 2000,
}

fn get_two_word_command(first: &str, second: &str) -> Cmd {
Expand Down Expand Up @@ -457,6 +458,7 @@ impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
ProtobufRequestType::ScriptFlush => RequestType::ScriptFlush,
ProtobufRequestType::ScriptKill => RequestType::ScriptKill,
ProtobufRequestType::ScriptShow => RequestType::ScriptShow,
ProtobufRequestType::FtCreate => RequestType::FtCreate,
}
}
}
Expand Down Expand Up @@ -685,6 +687,7 @@ impl RequestType {
RequestType::ScriptExists => Some(get_two_word_command("SCRIPT", "EXISTS")),
RequestType::ScriptFlush => Some(get_two_word_command("SCRIPT", "FLUSH")),
RequestType::ScriptKill => Some(get_two_word_command("SCRIPT", "KILL")),
RequestType::FtCreate => Some(cmd("FT.CREATE")),
}
}
}
25 changes: 25 additions & 0 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static command_request.CommandRequestOuterClass.RequestType.ExpireTime;
import static command_request.CommandRequestOuterClass.RequestType.FCall;
import static command_request.CommandRequestOuterClass.RequestType.FCallReadOnly;
import static command_request.CommandRequestOuterClass.RequestType.FtCreate;
import static command_request.CommandRequestOuterClass.RequestType.GeoAdd;
import static command_request.CommandRequestOuterClass.RequestType.GeoDist;
import static command_request.CommandRequestOuterClass.RequestType.GeoHash;
Expand Down Expand Up @@ -209,6 +210,7 @@
import glide.api.commands.StreamBaseCommands;
import glide.api.commands.StringBaseCommands;
import glide.api.commands.TransactionsBaseCommands;
import glide.api.commands.VectorSearchBaseCommands;
import glide.api.models.ClusterValue;
import glide.api.models.GlideString;
import glide.api.models.PubSubMessage;
Expand Down Expand Up @@ -264,6 +266,8 @@
import glide.api.models.commands.stream.StreamReadGroupOptions;
import glide.api.models.commands.stream.StreamReadOptions;
import glide.api.models.commands.stream.StreamTrimOptions;
import glide.api.models.commands.vss.FTCreateOptions.FieldInfo;
import glide.api.models.commands.vss.FTCreateOptions.IndexType;
import glide.api.models.configuration.BaseClientConfiguration;
import glide.api.models.configuration.BaseSubscriptionConfiguration;
import glide.api.models.exceptions.ConfigurationError;
Expand All @@ -279,6 +283,7 @@
import glide.managers.CommandManager;
import glide.managers.ConnectionManager;
import glide.utils.ArgsBuilder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
Expand Down Expand Up @@ -310,6 +315,7 @@ public abstract class BaseClient
HyperLogLogBaseCommands,
GeospatialIndicesBaseCommands,
ScriptingAndFunctionsBaseCommands,
VectorSearchBaseCommands,
TransactionsBaseCommands,
PubSubBaseCommands {

Expand Down Expand Up @@ -5142,4 +5148,23 @@ public CompletableFuture<Long> wait(long numreplicas, long timeout) {
new String[] {Long.toString(numreplicas), Long.toString(timeout)},
this::handleLongResponse);
}

@Override
public CompletableFuture<String> ftcreate(
@NonNull String indexName,
@NonNull IndexType indexType,
@NonNull String[] prefixes,
@NonNull FieldInfo[] fields) {
var args = new ArrayList<>(List.of(indexName, "ON", indexType.toString()));
if (prefixes.length > 0) {
args.add("PREFIX");
args.add(Integer.toString(prefixes.length));
args.addAll(List.of(prefixes));
}
args.add("SCHEMA");
Arrays.stream(fields).forEach(f -> args.addAll(List.of(f.toArgs())));

return commandManager.submitNewCommand(
FtCreate, args.toArray(String[]::new), this::handleStringResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.commands;

import glide.api.models.commands.vss.FTCreateOptions.FieldInfo;
import glide.api.models.commands.vss.FTCreateOptions.IndexType;
import java.util.concurrent.CompletableFuture;

public interface VectorSearchBaseCommands {
// TODO GlideString???
/**
* Creates an index and initiates a backfill of that index.
*
* @see TODO
* @param indexName Key name where index is stored.
* @param indexType The index type.
* @param prefixes (Optional) A list of prefixes of index definitions
* @param fields Fields to populate into the index.
* @return <code>OK</code>.
* @example
* <pre>{@code
* // TODO
* }</pre>
*/
CompletableFuture<String> ftcreate(
String indexName, IndexType indexType, String[] prefixes, FieldInfo[] fields);
}
Loading

0 comments on commit 9e3ce53

Please sign in to comment.