Skip to content

Commit d54772d

Browse files
committed
Replace usages of JedisPooled with RedisClient
1 parent 2605da7 commit d54772d

File tree

41 files changed

+510
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+510
-329
lines changed

src/main/java/redis/clients/jedis/mcf/PingStrategy.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import redis.clients.jedis.Endpoint;
77
import redis.clients.jedis.HostAndPort;
88
import redis.clients.jedis.JedisClientConfig;
9-
import redis.clients.jedis.JedisPooled;
9+
import redis.clients.jedis.RedisClient;
1010
import redis.clients.jedis.UnifiedJedis;
1111
import redis.clients.jedis.MultiDbConfig.StrategySupplier;
1212

@@ -24,7 +24,8 @@ public PingStrategy(HostAndPort hostAndPort, JedisClientConfig jedisClientConfig
2424
HealthCheckStrategy.Config config) {
2525
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
2626
poolConfig.setMaxTotal(MAX_HEALTH_CHECK_POOL_SIZE);
27-
this.jedis = new JedisPooled(hostAndPort, jedisClientConfig, poolConfig);
27+
this.jedis = RedisClient.builder().hostAndPort(hostAndPort).clientConfig(jedisClientConfig)
28+
.poolConfig(poolConfig).build();
2829
this.config = config;
2930
}
3031

src/test/java/io/redis/examples/SearchQuickstartExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class SearchQuickstartExample {
3737
public void run() {
3838
// STEP_START connect
3939
// UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
40-
JedisPooled jedis = new JedisPooled("localhost", 6379);
40+
RedisClient jedis = new RedisClient("localhost", 6379);
4141
// STEP_END
4242
// REMOVE_START
4343
try {

src/test/java/redis/clients/jedis/JedisPooledTest.java renamed to src/test/java/redis/clients/jedis/RedisClientTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import redis.clients.jedis.exceptions.JedisException;
2323

2424
@Tag("integration")
25-
public class JedisPooledTest {
25+
public class RedisClientTest {
2626

2727
private static final EndpointConfig endpointStandalone7 = HostAndPorts.getRedisEndpoint(
2828
"standalone7-with-lfu-policy");
@@ -31,7 +31,7 @@ public class JedisPooledTest {
3131

3232
@Test
3333
public void checkCloseableConnections() {
34-
JedisPooled pool = JedisPooled.builder()
34+
RedisClient pool = RedisClient.builder()
3535
.hostAndPort(endpointStandalone7.getHost(), endpointStandalone7.getPort())
3636
.clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000).build()).build();
3737
pool.set("foo", "bar");
@@ -42,7 +42,7 @@ public void checkCloseableConnections() {
4242

4343
@Test
4444
public void checkResourceWithConfig() {
45-
try (JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort())
45+
try (RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort())
4646
.clientConfig(DefaultJedisClientConfig.builder().socketTimeoutMillis(5000).build())
4747
.build()) {
4848

@@ -59,7 +59,7 @@ public void checkPoolOverflow() {
5959
config.setMaxTotal(1);
6060
config.setBlockWhenExhausted(false);
6161
try (
62-
JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort())
62+
RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort())
6363
.poolConfig(config).build();
6464
Connection jedis = pool.getPool().getResource()) {
6565
assertThrows(JedisException.class, () -> pool.getPool().getResource());
@@ -74,7 +74,7 @@ public void startWithUrlString() {
7474
j.set("foo", "bar");
7575
}
7676

77-
try (JedisPooled pool = JedisPooled.builder()
77+
try (RedisClient pool = RedisClient.builder()
7878
.fromURI(endpointStandalone1.getURIBuilder()
7979
.credentials("", endpointStandalone1.getPassword()).path("/2").build().toString())
8080
.build()) {
@@ -90,7 +90,7 @@ public void startWithUrl() throws URISyntaxException {
9090
j.set("foo", "bar");
9191
}
9292

93-
try (JedisPooled pool = JedisPooled.builder().fromURI(endpointStandalone1.getURIBuilder()
93+
try (RedisClient pool = RedisClient.builder().fromURI(endpointStandalone1.getURIBuilder()
9494
.credentials("", endpointStandalone1.getPassword()).path("/2").build()).build()) {
9595
assertEquals("bar", pool.get("foo"));
9696
}
@@ -99,19 +99,19 @@ public void startWithUrl() throws URISyntaxException {
9999
@Test
100100
public void shouldThrowExceptionForInvalidURI() {
101101
assertThrows(Exception.class,
102-
() -> JedisPooled.builder().fromURI(new URI("localhost:6380")).build());
102+
() -> RedisClient.builder().fromURI(new URI("localhost:6380")).build());
103103
}
104104

105105
@Test
106106
public void allowUrlWithNoDBAndNoPassword() throws URISyntaxException {
107-
JedisPooled.builder().fromURI(endpointStandalone1.getURI().toString()).build().close();
108-
JedisPooled.builder().fromURI(endpointStandalone1.getURI()).build().close();
107+
RedisClient.builder().fromURI(endpointStandalone1.getURI().toString()).build().close();
108+
RedisClient.builder().fromURI(endpointStandalone1.getURI()).build().close();
109109
}
110110

111111
@Test
112112
public void customClientName() {
113113
try (
114-
JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort())
114+
RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort())
115115
.clientConfig(
116116
DefaultJedisClientConfig.builder().clientName("my_shiny_client_name").build())
117117
.build();
@@ -123,7 +123,7 @@ public void customClientName() {
123123
@Test
124124
public void invalidClientName() {
125125
try (
126-
JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort())
126+
RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort())
127127
.clientConfig(
128128
DefaultJedisClientConfig.builder().clientName("invalid client name").build())
129129
.build();
@@ -137,7 +137,7 @@ public void invalidClientName() {
137137

138138
@Test
139139
public void getNumActiveWhenPoolIsClosed() {
140-
JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort())
140+
RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort())
141141
.build();
142142

143143
try (Connection j = pool.getPool().getResource()) {
@@ -150,7 +150,7 @@ public void getNumActiveWhenPoolIsClosed() {
150150

151151
@Test
152152
public void getNumActiveReturnsTheCorrectNumber() {
153-
try (JedisPooled pool = JedisPooled.builder()
153+
try (RedisClient pool = RedisClient.builder()
154154
.hostAndPort(endpointStandalone7.getHost(), endpointStandalone7.getPort())
155155
.clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000).build())
156156
.poolConfig(new ConnectionPoolConfig()).build()) {
@@ -171,7 +171,7 @@ public void getNumActiveReturnsTheCorrectNumber() {
171171

172172
@Test
173173
public void closeResourceTwice() {
174-
try (JedisPooled pool = JedisPooled.builder()
174+
try (RedisClient pool = RedisClient.builder()
175175
.hostAndPort(endpointStandalone7.getHost(), endpointStandalone7.getPort())
176176
.clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000).build())
177177
.poolConfig(new ConnectionPoolConfig()).build()) {
@@ -184,7 +184,7 @@ public void closeResourceTwice() {
184184

185185
@Test
186186
public void closeBrokenResourceTwice() {
187-
try (JedisPooled pool = JedisPooled.builder()
187+
try (RedisClient pool = RedisClient.builder()
188188
.hostAndPort(endpointStandalone7.getHost(), endpointStandalone7.getPort())
189189
.clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000).build())
190190
.poolConfig(new ConnectionPoolConfig()).build()) {
@@ -204,10 +204,10 @@ public void closeBrokenResourceTwice() {
204204

205205
@Test
206206
public void testResetValidCredentials() {
207-
DefaultRedisCredentialsProvider credentialsProvider =
207+
DefaultRedisCredentialsProvider credentialsProvider =
208208
new DefaultRedisCredentialsProvider(new DefaultRedisCredentials(null, "bad password"));
209209

210-
try (JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone1.getHostAndPort())
210+
try (RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone1.getHostAndPort())
211211
.clientConfig(
212212
DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider).build())
213213
.build()) {
@@ -269,7 +269,7 @@ public void cleanUp() {
269269
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
270270
poolConfig.setMaxTotal(1);
271271
poolConfig.setTestOnBorrow(true);
272-
try (JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone1.getHostAndPort())
272+
try (RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone1.getHostAndPort())
273273
.clientConfig(
274274
DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider).build())
275275
.poolConfig(poolConfig).build()) {

src/test/java/redis/clients/jedis/SSLOptionsJedisPooledTest.java renamed to src/test/java/redis/clients/jedis/SSLOptionsRedisClientTest.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import static org.junit.jupiter.api.Assertions.assertEquals;
1313

1414
@Tag("integration")
15-
public class SSLOptionsJedisPooledTest {
15+
public class SSLOptionsRedisClientTest {
1616

1717
protected static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0-tls");
1818

@@ -31,48 +31,56 @@ public static void prepare() {
3131

3232
@Test
3333
public void connectWithClientConfig() {
34-
try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(),
35-
endpoint.getClientConfigBuilder()
34+
try (RedisClient jedis = RedisClient.builder()
35+
.hostAndPort(endpoint.getHostAndPort())
36+
.clientConfig(endpoint.getClientConfigBuilder()
3637
.sslOptions(SslOptions.builder()
3738
.truststore(trustStorePath.toFile())
3839
.trustStoreType("jceks")
39-
.build()).build())) {
40+
.build()).build())
41+
.build()) {
4042
assertEquals("PONG", jedis.ping());
4143
}
4244
}
4345

4446
@Test
4547
public void connectWithSslInsecure() {
46-
try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(),
47-
endpoint.getClientConfigBuilder()
48+
try (RedisClient jedis = RedisClient.builder()
49+
.hostAndPort(endpoint.getHostAndPort())
50+
.clientConfig(endpoint.getClientConfigBuilder()
4851
.sslOptions(SslOptions.builder()
4952
.sslVerifyMode(SslVerifyMode.INSECURE)
50-
.build()).build())) {
53+
.build()).build())
54+
.build()) {
5155
assertEquals("PONG", jedis.ping());
5256
}
5357
}
5458

5559
@Test
5660
public void connectWithSslContextProtocol() {
57-
try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(),
58-
endpoint.getClientConfigBuilder()
61+
try (RedisClient jedis = RedisClient.builder()
62+
.hostAndPort(endpoint.getHostAndPort())
63+
.clientConfig(endpoint.getClientConfigBuilder()
5964
.sslOptions(SslOptions.builder()
6065
.sslProtocol("SSL")
6166
.truststore(trustStorePath.toFile())
6267
.trustStoreType("jceks")
63-
.build()).build())) {
68+
.build()).build())
69+
.build()) {
6470
assertEquals("PONG", jedis.ping());
6571
}
6672
}
6773

6874
@Test
6975
public void connectWithAcl() {
70-
try (JedisPooled jedis = new JedisPooled(aclEndpoint.getHostAndPort(),
71-
aclEndpoint.getClientConfigBuilder()
76+
try (RedisClient jedis = RedisClient.builder()
77+
.hostAndPort(aclEndpoint.getHostAndPort())
78+
.clientConfig(aclEndpoint.getClientConfigBuilder()
7279
.sslOptions(SslOptions.builder()
7380
.truststore(trustStorePath.toFile())
7481
.trustStoreType("jceks")
75-
.build()).build())) {
82+
.build()).build())
83+
.build()) {
7684
assertEquals("PONG", jedis.ping());
7785
}
7886
}

src/test/java/redis/clients/jedis/authentication/RedisEntraIDIntegrationTests.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
import redis.clients.jedis.EndpointConfig;
6666
import redis.clients.jedis.HostAndPort;
6767
import redis.clients.jedis.HostAndPorts;
68-
import redis.clients.jedis.JedisPooled;
68+
import redis.clients.jedis.RedisClient;
6969
import redis.clients.jedis.exceptions.JedisAccessControlException;
7070
import redis.clients.jedis.exceptions.JedisConnectionException;
7171
import redis.clients.jedis.scenario.FaultInjectionClient;
@@ -119,7 +119,10 @@ public void testJedisConfig() {
119119
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder()
120120
.authXManager(new AuthXManager(tokenAuthConfig)).build();
121121

122-
JedisPooled jedis = new JedisPooled(new HostAndPort("localhost", 6379), jedisConfig);
122+
RedisClient jedis = RedisClient.builder()
123+
.hostAndPort(new HostAndPort("localhost", 6379))
124+
.clientConfig(jedisConfig)
125+
.build();
123126
assertNotNull(jedis);
124127
assertEquals(1, counter.get());
125128

@@ -137,7 +140,10 @@ public void withSecret_azureServicePrincipalIntegrationTest() {
137140
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder()
138141
.authXManager(new AuthXManager(tokenAuthConfig)).build();
139142

140-
try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) {
143+
try (RedisClient jedis = RedisClient.builder()
144+
.hostAndPort(hnp)
145+
.clientConfig(jedisConfig)
146+
.build()) {
141147
String key = UUID.randomUUID().toString();
142148
jedis.set(key, "value");
143149
assertEquals("value", jedis.get(key));
@@ -156,7 +162,10 @@ public void withCertificate_azureServicePrincipalIntegrationTest() {
156162
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder()
157163
.authXManager(new AuthXManager(tokenAuthConfig)).build();
158164

159-
try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) {
165+
try (RedisClient jedis = RedisClient.builder()
166+
.hostAndPort(hnp)
167+
.clientConfig(jedisConfig)
168+
.build()) {
160169
String key = UUID.randomUUID().toString();
161170
jedis.set(key, "value");
162171
assertEquals("value", jedis.get(key));
@@ -198,7 +207,10 @@ public void renewalDuringOperationsTest() throws InterruptedException, Execution
198207
ExecutorService runner = Executors.newSingleThreadExecutor();
199208
runner.submit(() -> {
200209

201-
try (JedisPooled jedis = new JedisPooled(hnp, jedisClientConfig)) {
210+
try (RedisClient jedis = RedisClient.builder()
211+
.hostAndPort(hnp)
212+
.clientConfig(jedisClientConfig)
213+
.build()) {
202214
List<Future<?>> futures = new ArrayList<>();
203215
for (int i = 0; i < 5; i++) {
204216
Future<?> future = jedisExecutors.submit(() -> {
@@ -259,7 +271,10 @@ public void allConnectionsReauthTest() throws InterruptedException, ExecutionExc
259271
List<Future<?>> futures = new ArrayList<>();
260272
ExecutorService executor = Executors.newFixedThreadPool(5);
261273

262-
try (JedisPooled jedis = new JedisPooled(hnp, jedisClientConfig)) {
274+
try (RedisClient jedis = RedisClient.builder()
275+
.hostAndPort(hnp)
276+
.clientConfig(jedisClientConfig)
277+
.build()) {
263278
for (int i = 0; i < 5; i++) {
264279
Future<?> future = executor.submit(() -> {
265280
for (; System.currentTimeMillis() - startTime < 2000;) {
@@ -308,7 +323,10 @@ public void connectionAuthWithExpiredTokenTest() {
308323
DefaultJedisClientConfig jedisClientConfig = DefaultJedisClientConfig.builder()
309324
.authXManager(authXManager).build();
310325

311-
try (JedisPooled jedis = new JedisPooled(hnp, jedisClientConfig)) {
326+
try (RedisClient jedis = RedisClient.builder()
327+
.hostAndPort(hnp)
328+
.clientConfig(jedisClientConfig)
329+
.build()) {
312330
for (int i = 0; i < 50; i++) {
313331
String key = UUID.randomUUID().toString();
314332
jedis.set(key, "value");
@@ -346,7 +364,10 @@ public void networkPartitionEvictionTest() {
346364
DefaultJedisClientConfig jedisClientConfig = DefaultJedisClientConfig.builder()
347365
.authXManager(authXManager).build();
348366

349-
try (JedisPooled jedis = new JedisPooled(hnp, jedisClientConfig)) {
367+
try (RedisClient jedis = RedisClient.builder()
368+
.hostAndPort(hnp)
369+
.clientConfig(jedisClientConfig)
370+
.build()) {
350371
for (int i = 0; i < 5; i++) {
351372
String key = UUID.randomUUID().toString();
352373
jedis.set(key, "value");
@@ -413,7 +434,10 @@ public void withDefaultCredentials_azureCredentialsIntegrationTest() {
413434
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder()
414435
.authXManager(new AuthXManager(tokenAuthConfig)).build();
415436

416-
try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) {
437+
try (RedisClient jedis = RedisClient.builder()
438+
.hostAndPort(hnp)
439+
.clientConfig(jedisConfig)
440+
.build()) {
417441
String key = UUID.randomUUID().toString();
418442
jedis.set(key, "value");
419443
assertEquals("value", jedis.get(key));

src/test/java/redis/clients/jedis/authentication/RedisEntraIDManagedIdentityIntegrationTests.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import redis.clients.jedis.EndpointConfig;
1818
import redis.clients.jedis.HostAndPort;
1919
import redis.clients.jedis.HostAndPorts;
20-
import redis.clients.jedis.JedisPooled;
20+
import redis.clients.jedis.RedisClient;
2121

2222
import static org.junit.jupiter.api.Assertions.assertEquals;
2323
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@@ -55,7 +55,10 @@ public void withUserAssignedId_azureManagedIdentityIntegrationTest() {
5555
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder()
5656
.authXManager(new AuthXManager(tokenAuthConfig)).build();
5757

58-
try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) {
58+
try (RedisClient jedis = RedisClient.builder()
59+
.hostAndPort(hnp)
60+
.clientConfig(jedisConfig)
61+
.build()) {
5962
String key = UUID.randomUUID().toString();
6063
jedis.set(key, "value");
6164
assertEquals("value", jedis.get(key));
@@ -73,7 +76,10 @@ public void withSystemAssignedId_azureManagedIdentityIntegrationTest() {
7376
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder()
7477
.authXManager(new AuthXManager(tokenAuthConfig)).build();
7578

76-
try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) {
79+
try (RedisClient jedis = RedisClient.builder()
80+
.hostAndPort(hnp)
81+
.clientConfig(jedisConfig)
82+
.build()) {
7783
String key = UUID.randomUUID().toString();
7884
jedis.set(key, "value");
7985
assertEquals("value", jedis.get(key));

0 commit comments

Comments
 (0)