Skip to content

Commit b2c7a02

Browse files
committed
Merge branch 'master' into ft-profile-info
2 parents e41544a + a46700a commit b2c7a02

21 files changed

+659
-214
lines changed

.github/workflows/test-on-docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
fail-fast: false
3737
matrix:
3838
redis_version:
39-
- "8.0-M02"
39+
- "8.0-M04-pre"
4040
- "7.4.1"
4141
- "7.2.6"
4242
# - "6.2.16"

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
PATH := ./redis-git/src:${PATH}
22

33
# Supported test env versions
4-
SUPPORTED_TEST_ENV_VERSIONS := 8.0-M02 7.4.1 7.2.6 6.2.16
5-
DEFAULT_TEST_ENV_VERSION := 8.0-M02
4+
SUPPORTED_TEST_ENV_VERSIONS := 8.0-M04-pre, 8.0-M02 7.4.1 7.2.6 6.2.16
5+
DEFAULT_TEST_ENV_VERSION := 8.0-M04-pre
66
REDIS_ENV_WORK_DIR := $(or ${REDIS_ENV_WORK_DIR},/tmp/redis-env-work)
77

88
define REDIS1_CONF

src/main/java/redis/clients/jedis/CommandObjects.java

+4
Original file line numberDiff line numberDiff line change
@@ -3531,19 +3531,23 @@ public final CommandObject<Set<String>> ftTagVals(String indexName, String field
35313531
.add(fieldName), BuilderFactory.STRING_SET);
35323532
}
35333533

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

3540+
@Deprecated
35393541
public final CommandObject<Map<String, Object>> ftConfigGet(String indexName, String option) {
35403542
return directSearchCommand(ftConfigGet(option), indexName);
35413543
}
35423544

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

3550+
@Deprecated
35473551
public final CommandObject<String> ftConfigSet(String indexName, String option, String value) {
35483552
return directSearchCommand(ftConfigSet(option, value), indexName);
35493553
}

src/main/java/redis/clients/jedis/PipeliningBase.java

+4
Original file line numberDiff line numberDiff line change
@@ -3565,21 +3565,25 @@ public Response<Set<String>> ftTagVals(String indexName, String fieldName) {
35653565
}
35663566

35673567
@Override
3568+
@Deprecated
35683569
public Response<Map<String, Object>> ftConfigGet(String option) {
35693570
return appendCommand(commandObjects.ftConfigGet(option));
35703571
}
35713572

35723573
@Override
3574+
@Deprecated
35733575
public Response<Map<String, Object>> ftConfigGet(String indexName, String option) {
35743576
return appendCommand(commandObjects.ftConfigGet(indexName, option));
35753577
}
35763578

35773579
@Override
3580+
@Deprecated
35783581
public Response<String> ftConfigSet(String option, String value) {
35793582
return appendCommand(commandObjects.ftConfigSet(option, value));
35803583
}
35813584

35823585
@Override
3586+
@Deprecated
35833587
public Response<String> ftConfigSet(String indexName, String option, String value) {
35843588
return appendCommand(commandObjects.ftConfigSet(indexName, option, value));
35853589
}

src/main/java/redis/clients/jedis/UnifiedJedis.java

+4
Original file line numberDiff line numberDiff line change
@@ -4067,21 +4067,25 @@ public Set<String> ftTagVals(String indexName, String fieldName) {
40674067
}
40684068

40694069
@Override
4070+
@Deprecated
40704071
public Map<String, Object> ftConfigGet(String option) {
40714072
return executeCommand(commandObjects.ftConfigGet(option));
40724073
}
40734074

40744075
@Override
4076+
@Deprecated
40754077
public Map<String, Object> ftConfigGet(String indexName, String option) {
40764078
return executeCommand(commandObjects.ftConfigGet(indexName, option));
40774079
}
40784080

40794081
@Override
4082+
@Deprecated
40804083
public String ftConfigSet(String option, String value) {
40814084
return executeCommand(commandObjects.ftConfigSet(option, value));
40824085
}
40834086

40844087
@Override
4088+
@Deprecated
40854089
public String ftConfigSet(String indexName, String option, String value) {
40864090
return executeCommand(commandObjects.ftConfigSet(indexName, option, value));
40874091
}

src/main/java/redis/clients/jedis/search/RediSearchCommands.java

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Map;
66
import java.util.Set;
77

8+
import redis.clients.jedis.commands.ConfigCommands;
89
import redis.clients.jedis.resps.Tuple;
910
import redis.clients.jedis.search.aggr.AggregationBuilder;
1011
import redis.clients.jedis.search.aggr.AggregationResult;
@@ -107,12 +108,22 @@ Map<String, Map<String, Double>> ftSpellCheck(String index, String query,
107108

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

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

117+
@Deprecated
112118
Map<String, Object> ftConfigGet(String indexName, String option);
113119

120+
/**
121+
* @deprecated {@link ConfigCommands#configSet(java.lang.String, java.lang.String)} is used since Redis 8.
122+
*/
123+
@Deprecated
114124
String ftConfigSet(String option, String value);
115125

126+
@Deprecated
116127
String ftConfigSet(String indexName, String option, String value);
117128

118129
long ftSugAdd(String key, String string, double score);

src/main/java/redis/clients/jedis/search/RediSearchPipelineCommands.java

+4
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ Response<Map<String, Map<String, Double>>> ftSpellCheck(String index, String que
9595

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

98+
@Deprecated
9899
Response<Map<String, Object>> ftConfigGet(String option);
99100

101+
@Deprecated
100102
Response<Map<String, Object>> ftConfigGet(String indexName, String option);
101103

104+
@Deprecated
102105
Response<String> ftConfigSet(String option, String value);
103106

107+
@Deprecated
104108
Response<String> ftConfigSet(String indexName, String option, String value);
105109

106110
Response<Long> ftSugAdd(String key, String string, double score);

src/main/java/redis/clients/jedis/search/SearchProtocol.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public enum SearchCommand implements ProtocolCommand {
1616
EXPLAINCLI("FT.EXPLAINCLI"),
1717
AGGREGATE("FT.AGGREGATE"),
1818
CURSOR("FT.CURSOR"),
19-
CONFIG("FT.CONFIG"),
19+
@Deprecated CONFIG("FT.CONFIG"),
2020
ALIASADD("FT.ALIASADD"),
2121
ALIASUPDATE("FT.ALIASUPDATE"),
2222
ALIASDEL("FT.ALIASDEL"),
@@ -52,11 +52,12 @@ public enum SearchKeyword implements Rawable {
5252
SCHEMA, TEXT, TAG, NUMERIC, GEO, GEOSHAPE, VECTOR, VERBATIM, NOCONTENT, NOSTOPWORDS, WITHSCORES,
5353
LANGUAGE, INFIELDS, SORTBY, ASC, DESC, LIMIT, HIGHLIGHT, FIELDS, TAGS, SUMMARIZE, FRAGS, LEN,
5454
SEPARATOR, INKEYS, RETURN, FILTER, GEOFILTER, ADD, INCR, MAX, FUZZY, READ, DEL, DD, TEMPORARY,
55-
STOPWORDS, NOFREQS, NOFIELDS, NOOFFSETS, NOHL, SET, GET, ON, SORTABLE, UNF, PREFIX,
55+
STOPWORDS, NOFREQS, NOFIELDS, NOOFFSETS, NOHL, ON, SORTABLE, UNF, PREFIX,
5656
LANGUAGE_FIELD, SCORE, SCORE_FIELD, SCORER, PARAMS, AS, DIALECT, SLOP, TIMEOUT, INORDER,
5757
EXPANDER, MAXTEXTFIELDS, SKIPINITIALSCAN, WITHSUFFIXTRIE, NOSTEM, NOINDEX, PHONETIC, WEIGHT,
5858
CASESENSITIVE, LOAD, APPLY, GROUPBY, MAXIDLE, WITHCURSOR, DISTANCE, TERMS, INCLUDE, EXCLUDE,
59-
SEARCH, AGGREGATE, QUERY, LIMITED, COUNT, REDUCE, INDEXMISSING, INDEXEMPTY, ADDSCORES;
59+
SEARCH, AGGREGATE, QUERY, LIMITED, COUNT, REDUCE, INDEXMISSING, INDEXEMPTY, ADDSCORES,
60+
@Deprecated SET, @Deprecated GET;
6061

6162
private final byte[] raw;
6263

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// EXAMPLE: cmds_servermgmt
2+
// REMOVE_START
3+
package io.redis.examples;
4+
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
// REMOVE_END
8+
import java.util.Set;
9+
10+
import redis.clients.jedis.Jedis;
11+
// HIDE_START
12+
import redis.clients.jedis.UnifiedJedis;
13+
14+
public class CmdsServerMgmtExample {
15+
@Test
16+
public void run() {
17+
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
18+
// HIDE_END
19+
20+
// STEP_START flushall
21+
// REMOVE_START
22+
jedis.set("testkey1", "1");
23+
jedis.set("testkey2", "2");
24+
jedis.set("testkey3", "3");
25+
// REMOVE_END
26+
String flushAllResult1 = jedis.flushAll();
27+
System.out.println(flushAllResult1); // >>> OK
28+
29+
Set<String> flushAllResult2 = jedis.keys("*");
30+
System.out.println(flushAllResult2); // >>> []
31+
// STEP_END
32+
// REMOVE_START
33+
Assert.assertEquals("OK", flushAllResult1);
34+
Assert.assertEquals("[]", flushAllResult2.toString());
35+
// REMOVE_END
36+
37+
// STEP_START info
38+
// Note: you must use the `Jedis` class to access the `info`
39+
// command rather than `UnifiedJedis`.
40+
Jedis jedis2 = new Jedis("redis://localhost:6379");
41+
42+
String infoResult = jedis2.info();
43+
44+
// Check the first 8 characters of the result (the full `info` string
45+
// is much longer than this).
46+
System.out.println(infoResult.substring(0, 8)); // >>> # Server
47+
48+
jedis2.close();
49+
// STEP_END
50+
// REMOVE_START
51+
Assert.assertEquals("# Server", infoResult.substring(0, 8));
52+
// REMOVE_END
53+
54+
// HIDE_START
55+
jedis.close();
56+
}
57+
}
58+
// HIDE_END

src/test/java/io/redis/test/utils/RedisVersion.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package io.redis.test.utils;
22

3-
public class RedisVersion implements Comparable<RedisVersion>{
3+
public class RedisVersion implements Comparable<RedisVersion> {
44
public static final RedisVersion V6_0_0 = RedisVersion.of("6.0.0");
55
public static final RedisVersion V7_0_0 = RedisVersion.of("7.0.0");
66
public static final RedisVersion V7_2_0 = RedisVersion.of("7.2.0");
77
public static final RedisVersion V7_4 = RedisVersion.of("7.4");
8+
public static final RedisVersion V8_0_0_PRE = RedisVersion.of("7.9.0");
89
public static final RedisVersion V8_0_0 = RedisVersion.of("8.0.0");
910

1011
private final int major;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package redis.clients.jedis.authentication;
2+
3+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
4+
import static org.junit.Assert.assertEquals;
5+
import static org.mockito.ArgumentMatchers.any;
6+
import static org.mockito.Mockito.atLeast;
7+
import static org.mockito.Mockito.doAnswer;
8+
import static org.mockito.Mockito.spy;
9+
import static org.mockito.Mockito.verify;
10+
import static org.awaitility.Awaitility.await;
11+
import static org.awaitility.Durations.*;
12+
13+
import java.util.Collections;
14+
import java.util.List;
15+
import java.util.concurrent.CopyOnWriteArrayList;
16+
import java.util.concurrent.CountDownLatch;
17+
import java.util.concurrent.ExecutionException;
18+
import java.util.concurrent.ExecutorService;
19+
import java.util.concurrent.Executors;
20+
import java.util.concurrent.Future;
21+
22+
import org.junit.BeforeClass;
23+
import org.junit.Test;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
27+
import redis.clients.authentication.core.TokenAuthConfig;
28+
import redis.clients.authentication.entraid.EntraIDTokenAuthConfigBuilder;
29+
import redis.clients.jedis.Connection;
30+
import redis.clients.jedis.ConnectionPoolConfig;
31+
import redis.clients.jedis.DefaultJedisClientConfig;
32+
import redis.clients.jedis.EndpointConfig;
33+
import redis.clients.jedis.HostAndPort;
34+
import redis.clients.jedis.HostAndPorts;
35+
import redis.clients.jedis.JedisClientConfig;
36+
import redis.clients.jedis.JedisCluster;
37+
38+
public class RedisEntraIDClusterIntegrationTests {
39+
private static final Logger log = LoggerFactory
40+
.getLogger(RedisEntraIDClusterIntegrationTests.class);
41+
42+
private static EntraIDTestContext testCtx;
43+
private static EndpointConfig endpointConfig;
44+
private static HostAndPort hnp;
45+
46+
@BeforeClass
47+
public static void before() {
48+
try {
49+
testCtx = EntraIDTestContext.DEFAULT;
50+
endpointConfig = HostAndPorts.getRedisEndpoint("cluster-entraid-acl");
51+
hnp = endpointConfig.getHostAndPort();
52+
} catch (IllegalArgumentException e) {
53+
log.warn("Skipping test because no Redis endpoint is configured");
54+
org.junit.Assume.assumeTrue(false);
55+
}
56+
}
57+
58+
@Test
59+
public void testClusterInitWithAuthXManager() {
60+
TokenAuthConfig tokenAuthConfig = EntraIDTokenAuthConfigBuilder.builder()
61+
.lowerRefreshBoundMillis(1000).clientId(testCtx.getClientId())
62+
.secret(testCtx.getClientSecret()).authority(testCtx.getAuthority())
63+
.scopes(testCtx.getRedisScopes()).build();
64+
65+
int defaultDirections = 5;
66+
JedisClientConfig config = DefaultJedisClientConfig.builder()
67+
.authXManager(new AuthXManager(tokenAuthConfig)).build();
68+
69+
ConnectionPoolConfig DEFAULT_POOL_CONFIG = new ConnectionPoolConfig();
70+
71+
try (JedisCluster jc = new JedisCluster(hnp, config, defaultDirections,
72+
DEFAULT_POOL_CONFIG)) {
73+
74+
assertEquals("OK", jc.set("foo", "bar"));
75+
assertEquals("bar", jc.get("foo"));
76+
assertEquals(1, jc.del("foo"));
77+
}
78+
}
79+
80+
@Test
81+
public void testClusterWithReAuth() throws InterruptedException, ExecutionException {
82+
TokenAuthConfig tokenAuthConfig = EntraIDTokenAuthConfigBuilder.builder()
83+
// 0.00002F is to make it fit into 2 seconds, we need at least 2 attempt in 2 seconds
84+
// to trigger re-authentication.
85+
// For expiration time between 30 minutes to 12 hours
86+
// token renew will happen in from 36ms up to 864ms
87+
// If the received token has more than 12 hours to expire, this test will probably fail, and need to be adjusted.
88+
.expirationRefreshRatio(0.00002F).clientId(testCtx.getClientId())
89+
.secret(testCtx.getClientSecret()).authority(testCtx.getAuthority())
90+
.scopes(testCtx.getRedisScopes()).build();
91+
92+
AuthXManager authXManager = new AuthXManager(tokenAuthConfig);
93+
94+
authXManager = spy(authXManager);
95+
96+
List<Connection> connections = new CopyOnWriteArrayList<>();
97+
doAnswer(invocation -> {
98+
Connection connection = spy((Connection) invocation.getArgument(0));
99+
invocation.getArguments()[0] = connection;
100+
connections.add(connection);
101+
Object result = invocation.callRealMethod();
102+
return result;
103+
}).when(authXManager).addConnection(any(Connection.class));
104+
105+
JedisClientConfig config = DefaultJedisClientConfig.builder().authXManager(authXManager)
106+
.build();
107+
108+
ExecutorService executorService = Executors.newFixedThreadPool(2);
109+
CountDownLatch latch = new CountDownLatch(1);
110+
try (JedisCluster jc = new JedisCluster(Collections.singleton(hnp), config)) {
111+
Runnable task = () -> {
112+
while (latch.getCount() > 0) {
113+
assertEquals("OK", jc.set("foo", "bar"));
114+
}
115+
};
116+
Future task1 = executorService.submit(task);
117+
Future task2 = executorService.submit(task);
118+
119+
await().pollInterval(ONE_HUNDRED_MILLISECONDS).atMost(TWO_SECONDS)
120+
.until(connections::size, greaterThanOrEqualTo(2));
121+
122+
connections.forEach(conn -> {
123+
await().pollInterval(ONE_HUNDRED_MILLISECONDS).atMost(TWO_SECONDS)
124+
.untilAsserted(() -> verify(conn, atLeast(2)).reAuthenticate());
125+
});
126+
latch.countDown();
127+
task1.get();
128+
task2.get();
129+
} finally {
130+
latch.countDown();
131+
executorService.shutdown();
132+
}
133+
}
134+
}

0 commit comments

Comments
 (0)