Skip to content

Align Search APIs and behaviour with Redis 8.0+ #4173

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 21 additions & 21 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ protected RedisProtocol getProtocol() {
}

protected volatile CommandKeyArgumentPreProcessor keyPreProcessor = null;
private JedisBroadcastAndRoundRobinConfig broadcastAndRoundRobinConfig = null;
private Lock mapperLock = new ReentrantLock(true);
private Lock mapperLock = new ReentrantLock(true);
private volatile JsonObjectMapper jsonObjectMapper;
private final AtomicInteger searchDialect = new AtomicInteger(2); // DEFAULT_SEARCH_DIALECT = 2;

Expand All @@ -58,10 +57,6 @@ void setKeyArgumentPreProcessor(CommandKeyArgumentPreProcessor keyPreProcessor)
this.keyPreProcessor = keyPreProcessor;
}

void setBroadcastAndRoundRobinConfig(JedisBroadcastAndRoundRobinConfig config) {
this.broadcastAndRoundRobinConfig = config;
}

protected CommandArguments commandArguments(ProtocolCommand command) {
CommandArguments comArgs = new CommandArguments(command);
if (keyPreProcessor != null) comArgs.setKeyArgumentPreProcessor(keyPreProcessor);
Expand Down Expand Up @@ -2941,7 +2936,7 @@ public final CommandObject<List<Object>> xreadGroup(byte[] groupName, byte[] con
}

public final CommandObject<List<Map.Entry<byte[], List<StreamEntryBinary>>>> xreadGroupBinary(
byte[] groupName, byte[] consumer, XReadGroupParams xReadGroupParams,
byte[] groupName, byte[] consumer, XReadGroupParams xReadGroupParams,
Map.Entry<byte[], StreamEntryID>... streams) {
CommandArguments args = commandArguments(XREADGROUP)
.add(GROUP).add(groupName).add(consumer)
Expand All @@ -2956,7 +2951,7 @@ public final CommandObject<List<Map.Entry<byte[], List<StreamEntryBinary>>>> xre
}

public final CommandObject<Map<byte[], List<StreamEntryBinary>>> xreadGroupBinaryAsMap(
byte[] groupName, byte[] consumer, XReadGroupParams xReadGroupParams,
byte[] groupName, byte[] consumer, XReadGroupParams xReadGroupParams,
Map.Entry<byte[], StreamEntryID>... streams) {
CommandArguments args = commandArguments(XREADGROUP)
.add(GROUP).add(groupName).add(consumer)
Expand Down Expand Up @@ -3445,37 +3440,42 @@ public final CommandObject<Long> hsetObject(String key, Map<String, Object> hash
return new CommandObject<>(addFlatMapArgs(commandArguments(HSET).key(key), hash), BuilderFactory.LONG);
}

private boolean isRoundRobinSearchCommand() {
if (broadcastAndRoundRobinConfig == null) {
return true;
} else if (broadcastAndRoundRobinConfig.getRediSearchModeInCluster() == JedisBroadcastAndRoundRobinConfig.RediSearchMode.LIGHT) {
return false;
}
return true;
private boolean isRoundRobinSearchCommand(SearchCommand sc) {

return !(sc.equals(SearchCommand.SUGGET) || sc.equals(SearchCommand.SUGADD) || sc.equals(
SearchCommand.SUGLEN) || sc.equals(SearchCommand.SUGDEL) || sc.equals(
SearchCommand.CURSOR));
}

private CommandArguments checkAndRoundRobinSearchCommand(SearchCommand sc, String idx) {
CommandArguments ca = commandArguments(sc);
if (isRoundRobinSearchCommand()) {
if (isRoundRobinSearchCommand(sc)) {
ca.add(idx);
} else {
ca.key(idx);
}
return ca;
}

private CommandArguments checkAndRoundRobinSearchCommand(SearchCommand sc, String idx1, String idx2) {
private CommandArguments checkAndRoundRobinSearchCommand(SearchCommand sc, String idx1,
String idx2) {
CommandArguments ca = commandArguments(sc);
if (isRoundRobinSearchCommand()) {
if (isRoundRobinSearchCommand(sc)) {
ca.add(idx1).add(idx2);
} else {
ca.key(idx1).key(idx2);
}
return ca;
}

private CommandArguments checkAndRoundRobinSearchCommand(CommandArguments commandArguments, byte[] indexName) {
return isRoundRobinSearchCommand() ? commandArguments.add(indexName) : commandArguments.key(indexName);
private CommandArguments checkAndRoundRobinSearchCommand(SearchCommand sc, byte[] indexName) {
CommandArguments ca = commandArguments(sc);
if (isRoundRobinSearchCommand(sc)) {
ca.add(indexName);
} else {
ca.key(indexName);
}
return ca;
}

private <T> CommandObject<T> directSearchCommand(CommandObject<T> object, String indexName) {
Expand Down Expand Up @@ -3556,7 +3556,7 @@ public final CommandObject<SearchResult> ftSearch(byte[] indexName, Query query)
if (protocol == RedisProtocol.RESP3) {
throw new UnsupportedOperationException("binary ft.search is not implemented with resp3.");
}
return new CommandObject<>(checkAndRoundRobinSearchCommand(commandArguments(SearchCommand.SEARCH), indexName)
return new CommandObject<>(checkAndRoundRobinSearchCommand(SearchCommand.SEARCH, indexName)
.addParams(query.dialectOptional(searchDialect.get())), getSearchResultBuilder(null,
() -> new SearchResultBuilder(!query.getNoContent(), query.getWithScores(), false)));
}
Expand Down

This file was deleted.

Loading
Loading