Skip to content

Test modules CONFIG support #4043

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

Merged
merged 12 commits into from
Jan 30, 2025
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
Expand Up @@ -15,11 +15,9 @@
public abstract class JedisCommandsTestBase {

@Rule
public RedisVersionRule versionRule = new RedisVersionRule(
HostAndPorts.getRedisEndpoint("standalone0"));
public RedisVersionRule versionRule = new RedisVersionRule(endpoint);
@Rule
public EnabledOnCommandRule enabledOnCommandRule = new EnabledOnCommandRule(
HostAndPorts.getRedisEndpoint("standalone0"));
public EnabledOnCommandRule enabledOnCommandRule = new EnabledOnCommandRule(endpoint);

/**
* Input data for parameterized tests. In principle all subclasses of this
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public abstract class RedisModuleCommandsTestBase {

@Rule
public RedisVersionRule versionRule = new RedisVersionRule(hnp,DefaultJedisClientConfig.builder().build() );
public RedisVersionRule versionRule = new RedisVersionRule(hnp, DefaultJedisClientConfig.builder().build());

/**
* Input data for parameterized tests. In principle all subclasses of this
Expand All @@ -39,6 +39,7 @@ public static Collection<Object[]> data() {
protected static final HostAndPort hnp = HostAndPort.from(address);
protected final RedisProtocol protocol;

protected Jedis jedis;
protected UnifiedJedis client;

/**
Expand All @@ -65,15 +66,15 @@ public static void prepare() {

@Before
public void setUp() {
try (Jedis jedis = new Jedis(hnp)) {
jedis.flushAll();
}
jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().protocol(protocol).build());
jedis.flushAll();
client = new UnifiedJedis(hnp, DefaultJedisClientConfig.builder().protocol(protocol).build());
}

@After
public void tearDown() throws Exception {
client.close();
jedis.close();
}

}
Loading