Skip to content

Commit

Permalink
Test modules CONFIG support (#4043)
Browse files Browse the repository at this point in the history
* Test SEARCH module CONFIG support

* Test according to design doc with Redis 8.0-M03

* Set the version rule

* Deprecate FT.CONFIG command and keyworkds

* Shorten file name

* fix typo

* Redis 8.0-M03 image reports the version as 7.9.226

* Redis 8.0-M04-pre restored defaults

* Based on RedisModuleCommandsTestBase

* close resource
  • Loading branch information
sazzad16 authored Jan 30, 2025
1 parent 5e1b5c8 commit 34bbf00
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -3531,19 +3531,23 @@ public final CommandObject<Set<String>> ftTagVals(String indexName, String field
.add(fieldName), BuilderFactory.STRING_SET);
}

@Deprecated
public final CommandObject<Map<String, Object>> ftConfigGet(String option) {
return new CommandObject<>(commandArguments(SearchCommand.CONFIG).add(SearchKeyword.GET).add(option),
protocol == RedisProtocol.RESP3 ? BuilderFactory.AGGRESSIVE_ENCODED_OBJECT_MAP : BuilderFactory.ENCODED_OBJECT_MAP_FROM_PAIRS);
}

@Deprecated
public final CommandObject<Map<String, Object>> ftConfigGet(String indexName, String option) {
return directSearchCommand(ftConfigGet(option), indexName);
}

@Deprecated
public final CommandObject<String> ftConfigSet(String option, String value) {
return new CommandObject<>(commandArguments(SearchCommand.CONFIG).add(SearchKeyword.SET).add(option).add(value), BuilderFactory.STRING);
}

@Deprecated
public final CommandObject<String> ftConfigSet(String indexName, String option, String value) {
return directSearchCommand(ftConfigSet(option, value), indexName);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/PipeliningBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3565,21 +3565,25 @@ public Response<Set<String>> ftTagVals(String indexName, String fieldName) {
}

@Override
@Deprecated
public Response<Map<String, Object>> ftConfigGet(String option) {
return appendCommand(commandObjects.ftConfigGet(option));
}

@Override
@Deprecated
public Response<Map<String, Object>> ftConfigGet(String indexName, String option) {
return appendCommand(commandObjects.ftConfigGet(indexName, option));
}

@Override
@Deprecated
public Response<String> ftConfigSet(String option, String value) {
return appendCommand(commandObjects.ftConfigSet(option, value));
}

@Override
@Deprecated
public Response<String> ftConfigSet(String indexName, String option, String value) {
return appendCommand(commandObjects.ftConfigSet(indexName, option, value));
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -4067,21 +4067,25 @@ public Set<String> ftTagVals(String indexName, String fieldName) {
}

@Override
@Deprecated
public Map<String, Object> ftConfigGet(String option) {
return executeCommand(commandObjects.ftConfigGet(option));
}

@Override
@Deprecated
public Map<String, Object> ftConfigGet(String indexName, String option) {
return executeCommand(commandObjects.ftConfigGet(indexName, option));
}

@Override
@Deprecated
public String ftConfigSet(String option, String value) {
return executeCommand(commandObjects.ftConfigSet(option, value));
}

@Override
@Deprecated
public String ftConfigSet(String indexName, String option, String value) {
return executeCommand(commandObjects.ftConfigSet(indexName, option, value));
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/redis/clients/jedis/search/RediSearchCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Map;
import java.util.Set;

import redis.clients.jedis.commands.ConfigCommands;
import redis.clients.jedis.resps.Tuple;
import redis.clients.jedis.search.aggr.AggregationBuilder;
import redis.clients.jedis.search.aggr.AggregationResult;
Expand Down Expand Up @@ -107,12 +108,22 @@ Map<String, Map<String, Double>> ftSpellCheck(String index, String query,

Set<String> ftTagVals(String indexName, String fieldName);

/**
* @deprecated {@link ConfigCommands#configGet(java.lang.String)} is used since Redis 8.
*/
@Deprecated
Map<String, Object> ftConfigGet(String option);

@Deprecated
Map<String, Object> ftConfigGet(String indexName, String option);

/**
* @deprecated {@link ConfigCommands#configSet(java.lang.String, java.lang.String)} is used since Redis 8.
*/
@Deprecated
String ftConfigSet(String option, String value);

@Deprecated
String ftConfigSet(String indexName, String option, String value);

long ftSugAdd(String key, String string, double score);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ Response<Map<String, Map<String, Double>>> ftSpellCheck(String index, String que

Response<Set<String>> ftTagVals(String indexName, String fieldName);

@Deprecated
Response<Map<String, Object>> ftConfigGet(String option);

@Deprecated
Response<Map<String, Object>> ftConfigGet(String indexName, String option);

@Deprecated
Response<String> ftConfigSet(String option, String value);

@Deprecated
Response<String> ftConfigSet(String indexName, String option, String value);

Response<Long> ftSugAdd(String key, String string, double score);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/redis/clients/jedis/search/SearchProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum SearchCommand implements ProtocolCommand {
EXPLAINCLI("FT.EXPLAINCLI"),
AGGREGATE("FT.AGGREGATE"),
CURSOR("FT.CURSOR"),
CONFIG("FT.CONFIG"),
@Deprecated CONFIG("FT.CONFIG"),
ALIASADD("FT.ALIASADD"),
ALIASUPDATE("FT.ALIASUPDATE"),
ALIASDEL("FT.ALIASDEL"),
Expand Down Expand Up @@ -52,11 +52,12 @@ public enum SearchKeyword implements Rawable {
SCHEMA, TEXT, TAG, NUMERIC, GEO, GEOSHAPE, VECTOR, VERBATIM, NOCONTENT, NOSTOPWORDS, WITHSCORES,
LANGUAGE, INFIELDS, SORTBY, ASC, DESC, LIMIT, HIGHLIGHT, FIELDS, TAGS, SUMMARIZE, FRAGS, LEN,
SEPARATOR, INKEYS, RETURN, FILTER, GEOFILTER, ADD, INCR, MAX, FUZZY, READ, DEL, DD, TEMPORARY,
STOPWORDS, NOFREQS, NOFIELDS, NOOFFSETS, NOHL, SET, GET, ON, SORTABLE, UNF, PREFIX,
STOPWORDS, NOFREQS, NOFIELDS, NOOFFSETS, NOHL, ON, SORTABLE, UNF, PREFIX,
LANGUAGE_FIELD, SCORE, SCORE_FIELD, SCORER, PARAMS, AS, DIALECT, SLOP, TIMEOUT, INORDER,
EXPANDER, MAXTEXTFIELDS, SKIPINITIALSCAN, WITHSUFFIXTRIE, NOSTEM, NOINDEX, PHONETIC, WEIGHT,
CASESENSITIVE, LOAD, APPLY, GROUPBY, MAXIDLE, WITHCURSOR, DISTANCE, TERMS, INCLUDE, EXCLUDE,
SEARCH, AGGREGATE, QUERY, LIMITED, COUNT, REDUCE, INDEXMISSING, INDEXEMPTY, ADDSCORES;
SEARCH, AGGREGATE, QUERY, LIMITED, COUNT, REDUCE, INDEXMISSING, INDEXEMPTY, ADDSCORES,
@Deprecated SET, @Deprecated GET;

private final byte[] raw;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package redis.clients.jedis.modules;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import io.redis.test.annotations.SinceRedisVersion;
import java.util.Collections;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import redis.clients.jedis.RedisProtocol;
import redis.clients.jedis.exceptions.JedisDataException;

@SinceRedisVersion(value = "7.9.0")
@RunWith(Parameterized.class)
public class ConsolidatedConfigurationCommandsTest extends RedisModuleCommandsTestBase {

public ConsolidatedConfigurationCommandsTest(RedisProtocol redisProtocol) {
super(redisProtocol);
}

@Test
public void setSearchConfigGloballyTest() {
final String configParam = "search-default-dialect";
// confirm default
assertEquals(Collections.singletonMap(configParam, "1"), jedis.configGet(configParam));

try {
assertEquals("OK", jedis.configSet(configParam, "2"));
assertEquals(Collections.singletonMap(configParam, "2"), jedis.configGet(configParam));

} finally {
// restore to default
assertEquals("OK", jedis.configSet(configParam, "1"));
}
}

@Test
public void setReadOnlySearchConfigTest() {
JedisDataException de = assertThrows(JedisDataException.class, () -> jedis.configSet("search-max-doctablesize", "10"));
assertThat(de.getMessage(), Matchers.not(Matchers.emptyOrNullString()));
}

@Test
public void getSearchConfigSettingTest() {
assertThat(jedis.configGet("search-timeout"), aMapWithSize(1));
}

@Test
public void getTSConfigSettingTest() {
assertThat(jedis.configGet("ts-retention-policy"), aMapWithSize(1));
}

@Test
public void getBFConfigSettingTest() {
assertThat(jedis.configGet("bf-error-rate"), aMapWithSize(1));
}

@Test
public void getCFConfigSettingTest() {
assertThat(jedis.configGet("cf-initial-size"), aMapWithSize(1));
}

@Test
public void getAllConfigSettings() {
assertThat(jedis.configGet("*").size(), Matchers.greaterThan(0));
}
}

0 comments on commit 34bbf00

Please sign in to comment.