diff --git a/README.md b/README.md index e5e0280650..9c912a8b02 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,10 @@ Next, you'll need to connect to Redis. Consider installing a redis server with d docker run -p 6379:6379 -it redis:latest ``` -For many applications, it's best to use a connection pool. You can instantiate a JedisPooled like so: +You can instantiate a RedisClient like so: ```java -JedisPooled jedis = new JedisPooled("localhost", 6379); +RedisClient jedis = RedisClient.builder().hostAndPort("localhost", 6379).build(); ``` Now you can send commands: @@ -81,16 +81,16 @@ jedis.sadd("planets", "Venus"); ## Connecting to a Redis cluster Jedis lets you connect to Redis Clusters, supporting the [Redis Cluster Specification](https://redis.io/topics/cluster-spec). -To do this, you'll need to connect using `JedisCluster`. See the example below: +To do this, you'll need to connect using `RedisClusterClient`. See the example below: ```java Set jedisClusterNodes = new HashSet(); jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7379)); jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7380)); -JedisCluster jedis = new JedisCluster(jedisClusterNodes); +RedisClusterClient jedis = RedisClusterClient.builder().nodes(jedisClusterNodes).build(); ``` -Now you can use the `JedisCluster` instance and send commands like you would with a standard pooled connection: +Now you can use the `RedisClusterClient` instance and send commands like you would with a standard pooled connection: ```java jedis.sadd("planets", "Mars"); diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 0f7c2bbbe1..cceb373784 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -255,16 +255,16 @@ public class DockerNATMapper implements HostAndPortMapper { } ``` -Then, instantiate this class and pass it to the JedisCluster constructor: +Then, instantiate this class and pass it to the RedisClusterClient builder: ```java Map nodeMapping = new HashMap<>(); -nodeMapping.put(new HostAndPort("172.18.0.2", 6379), new HostAndPort("my-redis.example.com", 7001)); +nodeMapping.put(new HostAndPort("172.18.0.2", 6379), new HostAndPort("my-redis.example.com", 7001)); nodeMapping.put(new HostAndPort("172.18.0.3", 6379), new HostAndPort("my-redis.example.com", 7002)); nodeMapping.put(new HostAndPort("172.18.0.4", 6379), new HostAndPort("my-redis.example.com", 7002)); Set initialNodes = new HashSet<>(); -// seed node +// seed node initialNodes.add(new HostAndPort("my-redis.example.com", 7001)); HostAndPortMapper mapper = new DockerNATMapper(nodeMapping); @@ -275,10 +275,13 @@ JedisClientConfig jedisClientConfig = DefaultJedisClientConfig.builder() .hostAndPortMapper(mapper) .build(); -JedisCluster jedisCluster = new JedisCluster(initialNodes, jedisClientConfig); +RedisClusterClient jedisCluster = RedisClusterClient.builder() + .nodes(initialNodes) + .clientConfig(jedisClientConfig) + .build(); ``` -Now, when JedisCluster discovers a node at "172.18.0.2:6379", the mapper will translate it to "localhost:7001" before attempting to connect. +Now, when RedisClusterClient discovers a node at "172.18.0.2:6379", the mapper will translate it to "localhost:7001" before attempting to connect. ### Implementing with a Lambda Expression Since HostAndPortMapper is a functional interface (it has only one abstract method), you can also provide the implementation more concisely using a lambda expression. This is often preferred for simpler, inline mapping logic. @@ -300,7 +303,10 @@ JedisClientConfig jedisClientConfig = DefaultJedisClientConfig.builder() .hostAndPortMapper(mapper) .build(); -JedisCluster jedisCluster = new JedisCluster(initialNodes, jedisClientConfig); +RedisClusterClient jedisCluster = RedisClusterClient.builder() + .nodes(initialNodes) + .clientConfig(jedisClientConfig) + .build(); ``` ## Miscellaneous diff --git a/docs/redisearch.md b/docs/redisearch.md index c446de0b41..428ad310bd 100644 --- a/docs/redisearch.md +++ b/docs/redisearch.md @@ -4,20 +4,20 @@ To use RediSearch features with Jedis, you'll need to use an implementation of R ## Creating the RediSearch client -Initializing the client with JedisPooled: +Initializing the client with RedisClient: ```java -JedisPooled client = new JedisPooled("localhost", 6379); +RedisClient client = RedisClient.builder().hostAndPort("localhost", 6379).build(); ``` -Initializing the client with JedisCluster: +Initializing the client with RedisClusterClient: ```java Set nodes = new HashSet<>(); nodes.add(new HostAndPort("127.0.0.1", 7379)); nodes.add(new HostAndPort("127.0.0.1", 7380)); -JedisCluster client = new JedisCluster(nodes); +RedisClusterClient client = RedisClusterClient.builder().nodes(nodes).build(); ``` ## Indexing and querying diff --git a/docs/redisjson.md b/docs/redisjson.md index de9d01c415..751c435d83 100644 --- a/docs/redisjson.md +++ b/docs/redisjson.md @@ -9,20 +9,20 @@ Let's see how this works. ## Creating with RedisJSON client -First, let's create a `JedisPooled` client instance: +First, let's create a `RedisClient` client instance: ```java -JedisPooled client = new JedisPooled("localhost", 6479); +RedisClient client = RedisClient.builder().hostAndPort("localhost", 6479).build(); ``` -Or, a `JedisCluster` client instance: +Or, a `RedisClusterClient` client instance: ```java Set nodes = new HashSet<>(); nodes.add(new HostAndPort("127.0.0.1", 7379)); nodes.add(new HostAndPort("127.0.0.1", 7380)); -JedisCluster client = new JedisCluster(nodes); +RedisClusterClient client = RedisClusterClient.builder().nodes(nodes).build(); ``` Now we can start working with JSON. For these examples, we'll be using [GSON](https://github.com/google/gson) diff --git a/hbase-formatter.xml b/hbase-formatter.xml index 48995ab26d..0becf15531 100644 --- a/hbase-formatter.xml +++ b/hbase-formatter.xml @@ -16,7 +16,7 @@ - + diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index f349b225e0..0b8b1d2318 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -32,6 +32,62 @@ import redis.clients.jedis.util.KeyValue; import redis.clients.jedis.util.Pool; +/** + * Jedis is a lightweight Redis client that uses a single, non-pooled connection to Redis. + *

+ * Important: For most production use cases, {@link RedisClient} is the recommended and + * preferred option. {@code RedisClient} provides connection pooling, better resource management, + * and improved performance for typical applications. + *

+ *

+ * When to use Jedis: + *

+ *
    + *
  • Short-lived scripts or utilities: When you need a simple, lightweight client for + * one-off operations or command-line tools.
  • + *
  • Testing and development: For unit tests or local development where connection pooling + * overhead is unnecessary.
  • + *
  • Fine-grained connection control: Advanced scenarios requiring explicit control over + * individual connections, such as managing connection lifecycle manually or implementing custom + * connection strategies.
  • + *
  • Single-threaded applications: Applications that execute Redis commands sequentially + * from a single thread and don't benefit from connection pooling.
  • + *
+ *

+ * When to use RedisClient instead: + *

+ *
    + *
  • Production applications: Any multi-threaded or high-throughput application should use + * {@link RedisClient} for its connection pooling capabilities.
  • + *
  • Web applications: Server applications handling concurrent requests benefit from + * connection pooling to avoid connection overhead.
  • + *
  • Long-running services: Applications that maintain persistent connections to Redis + * should use {@link RedisClient} for better resource management.
  • + *
  • Default choice: If you're unsure which to use, choose {@link RedisClient}.
  • + *
+ *

+ * Usage example: + *

+ * + *
+ * {
+ *   @code
+ *   // Simple usage for a short-lived operation
+ *   try (Jedis jedis = new Jedis("localhost", 6379)) {
+ *     jedis.set("key", "value");
+ *     String value = jedis.get("key");
+ *   }
+ * }
+ * 
+ *

+ * Note: Each {@code Jedis} instance maintains a single connection. For concurrent access + * from multiple threads, either use {@link RedisClient} with connection pooling, or create + * separate {@code Jedis} instances per thread (not recommended for production). + *

+ * + * @see RedisClient for the recommended pooled client for production use + * @see JedisPool for legacy pooled connections (deprecated, use RedisClient instead) + */ public class Jedis implements ServerCommands, DatabaseCommands, JedisCommands, JedisBinaryCommands, ControlCommands, ControlBinaryCommands, ClusterCommands, ModuleCommands, GenericControlCommands, SentinelCommands, CommandCommands, Closeable { diff --git a/src/main/java/redis/clients/jedis/JedisCluster.java b/src/main/java/redis/clients/jedis/JedisCluster.java index a733e5d027..8bafcbdfd7 100644 --- a/src/main/java/redis/clients/jedis/JedisCluster.java +++ b/src/main/java/redis/clients/jedis/JedisCluster.java @@ -18,6 +18,14 @@ import redis.clients.jedis.providers.ConnectionProvider; import redis.clients.jedis.util.JedisClusterCRC16; +/** + * JedisCluster is a client for Redis Cluster deployments. + * + * @deprecated Use {@link RedisClusterClient} instead. RedisClusterClient provides the same functionality + * with a cleaner API and simplified constructor options. For basic usage, simple + * constructors are available. For advanced configuration, use {@link RedisClusterClient#builder()}. + */ +@Deprecated public class JedisCluster extends UnifiedJedis { public static final String INIT_NO_ERROR_PROPERTY = "jedis.cluster.initNoError"; diff --git a/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java b/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java index ab8b6622c3..367f65acf7 100644 --- a/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java +++ b/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java @@ -31,7 +31,7 @@ import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.util.SafeEncoder; -import static redis.clients.jedis.JedisCluster.INIT_NO_ERROR_PROPERTY; +import static redis.clients.jedis.RedisClusterClient.INIT_NO_ERROR_PROPERTY; @Internal public class JedisClusterInfoCache { diff --git a/src/main/java/redis/clients/jedis/JedisFactory.java b/src/main/java/redis/clients/jedis/JedisFactory.java index 0ff5bebe1c..dc92252c17 100644 --- a/src/main/java/redis/clients/jedis/JedisFactory.java +++ b/src/main/java/redis/clients/jedis/JedisFactory.java @@ -17,9 +17,19 @@ import redis.clients.jedis.util.JedisURIHelper; /** - * PoolableObjectFactory custom impl. + * PooledObjectFactory implementation for creating and managing {@link Jedis} instances in connection pools. + *

+ * This factory is used internally by {@link JedisPool} and {@link JedisSentinelPool} to create, validate, + * and destroy pooled Jedis connections. + *

+ * + * @deprecated JedisFactory is used exclusively with the deprecated {@link JedisPool} and {@link JedisSentinelPool} + * classes. For modern Redis clients ({@link RedisClient}, {@link RedisSentinelClient}), the framework + * uses {@link ConnectionFactory} internally, which manages {@link Connection} objects instead of + * {@link Jedis} instances. There is no direct replacement for JedisFactory as connection management + * is handled automatically by the new client architecture. */ -// Legacy +@Deprecated public class JedisFactory implements PooledObjectFactory { private static final Logger logger = LoggerFactory.getLogger(JedisFactory.class); diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index 3cc9aad107..9ef59d48f5 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -13,7 +13,14 @@ import redis.clients.jedis.util.JedisURIHelper; import redis.clients.jedis.util.Pool; -// Legacy +/** + * JedisPool is a pooled connection client for standalone Redis servers. + * + * @deprecated Use {@link RedisClient} instead. RedisClient provides the same functionality + * with a cleaner API and simplified constructor options. For basic usage, simple + * constructors are available. For advanced configuration, use {@link RedisClient#builder()}. + */ +@Deprecated public class JedisPool extends Pool { private static final Logger log = LoggerFactory.getLogger(JedisPool.class); diff --git a/src/main/java/redis/clients/jedis/JedisPoolConfig.java b/src/main/java/redis/clients/jedis/JedisPoolConfig.java index 476d2e3f09..9013dfb998 100644 --- a/src/main/java/redis/clients/jedis/JedisPoolConfig.java +++ b/src/main/java/redis/clients/jedis/JedisPoolConfig.java @@ -3,6 +3,15 @@ import java.time.Duration; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +/** + * Configuration class for {@link JedisPool} connection pooling. + * + * @deprecated JedisPoolConfig is used with the deprecated {@link JedisPool} and {@link JedisSentinelPool} classes. + * Use {@link ConnectionPoolConfig} instead, which is designed for the modern {@link RedisClient} + * and {@link RedisSentinelClient} classes. ConnectionPoolConfig provides the same pooling configuration + * options with better integration into the new client architecture. + */ +@Deprecated public class JedisPoolConfig extends GenericObjectPoolConfig { public JedisPoolConfig() { diff --git a/src/main/java/redis/clients/jedis/JedisPooled.java b/src/main/java/redis/clients/jedis/JedisPooled.java index ece0341977..6e6711e088 100644 --- a/src/main/java/redis/clients/jedis/JedisPooled.java +++ b/src/main/java/redis/clients/jedis/JedisPooled.java @@ -18,6 +18,14 @@ import redis.clients.jedis.util.JedisURIHelper; import redis.clients.jedis.util.Pool; +/** + * JedisPooled is a pooled connection client for standalone Redis servers. + * + * @deprecated Use {@link RedisClient} instead. RedisClient provides the same functionality + * with a cleaner API and simplified constructor options. For basic usage, simple + * constructors are available. For advanced configuration, use {@link RedisClient#builder()}. + */ +@Deprecated public class JedisPooled extends UnifiedJedis { public JedisPooled() { diff --git a/src/main/java/redis/clients/jedis/JedisSentinelPool.java b/src/main/java/redis/clients/jedis/JedisSentinelPool.java index c9c3626510..027a444ddb 100644 --- a/src/main/java/redis/clients/jedis/JedisSentinelPool.java +++ b/src/main/java/redis/clients/jedis/JedisSentinelPool.java @@ -18,6 +18,14 @@ import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.util.Pool; +/** + * JedisSentinelPool is a pooled connection client for Redis Sentinel deployments. + * + * @deprecated Use {@link RedisSentinelClient} instead. RedisSentinelClient provides the same functionality + * with a cleaner API and simplified constructor options. For basic usage, simple + * constructors are available. For advanced configuration, use {@link RedisSentinelClient#builder()}. + */ +@Deprecated public class JedisSentinelPool extends Pool { private static final Logger LOG = LoggerFactory.getLogger(JedisSentinelPool.class); diff --git a/src/main/java/redis/clients/jedis/JedisSentineled.java b/src/main/java/redis/clients/jedis/JedisSentineled.java index efc4ff69c6..d00742e97a 100644 --- a/src/main/java/redis/clients/jedis/JedisSentineled.java +++ b/src/main/java/redis/clients/jedis/JedisSentineled.java @@ -11,6 +11,14 @@ import redis.clients.jedis.providers.ConnectionProvider; import redis.clients.jedis.providers.SentineledConnectionProvider; +/** + * JedisSentineled is a client for Redis Sentinel deployments. + * + * @deprecated Use {@link RedisSentinelClient} instead. RedisSentinelClient provides the same functionality + * with a cleaner API. Use {@link RedisSentinelClient#builder()} to configure the client + * with sentinel settings, master configuration, and connection pooling options. + */ +@Deprecated public class JedisSentineled extends UnifiedJedis { public JedisSentineled(String masterName, final JedisClientConfig masterClientConfig, diff --git a/src/main/java/redis/clients/jedis/RedisClient.java b/src/main/java/redis/clients/jedis/RedisClient.java new file mode 100644 index 0000000000..22a2ef0699 --- /dev/null +++ b/src/main/java/redis/clients/jedis/RedisClient.java @@ -0,0 +1,109 @@ +package redis.clients.jedis; + +import java.net.URI; + +import redis.clients.jedis.builders.StandaloneClientBuilder; +import redis.clients.jedis.csc.Cache; +import redis.clients.jedis.executors.CommandExecutor; +import redis.clients.jedis.providers.ConnectionProvider; +import redis.clients.jedis.providers.PooledConnectionProvider; +import redis.clients.jedis.util.JedisURIHelper; +import redis.clients.jedis.util.Pool; + +/** + * {@code RedisClient} is the recommended client for connecting to standalone Redis deployments. + *

+ * This class provides a modern, unified interface for interacting with Redis, supporting connection + * pooling, authentication, and configuration via a fluent builder API. + *

+ *

+ * {@code RedisClient} supersedes the deprecated {@link JedisPooled} and {@link UnifiedJedis} + * classes, offering improved usability and extensibility. For new applications, use + * {@code RedisClient} instead of the older classes. + *

+ *

+ * Example usage: + *

+ * + *
+ * {
+ *   @code
+ *   RedisClient client = RedisClient.builder().host("localhost").port(6379).build();
+ * }
+ * 
+ *

+ * For advanced configuration, see the {@link RedisClient.Builder} class. + *

+ */ +public class RedisClient extends UnifiedJedis { + + public RedisClient() { + this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT); + } + + /** + * WARNING: This constructor only accepts a uri string as {@code url}. + * {@link JedisURIHelper#isValid(java.net.URI)} can be used before this. + *

+ * To use a host string, {@link #RedisClient(java.lang.String, int)} can be used with + * {@link Protocol#DEFAULT_PORT}. + * @param url redis url + */ + public RedisClient(final String url) { + super(url); + } + + public RedisClient(final String host, final int port) { + this(new HostAndPort(host, port)); + } + + public RedisClient(final HostAndPort hostAndPort) { + super(hostAndPort); + } + + public RedisClient(final String host, final int port, final String user, final String password) { + super(new HostAndPort(host, port), + DefaultJedisClientConfig.builder().user(user).password(password).build()); + } + + public RedisClient(final URI uri) { + super(uri); + } + + private RedisClient(CommandExecutor commandExecutor, ConnectionProvider connectionProvider, + CommandObjects commandObjects, RedisProtocol redisProtocol, Cache cache) { + super(commandExecutor, connectionProvider, commandObjects, redisProtocol, cache); + } + + /** + * Fluent builder for {@link RedisClient} (standalone). + *

+ * Obtain an instance via {@link #builder()}. + *

+ */ + public static class Builder extends StandaloneClientBuilder { + + @Override + protected RedisClient createClient() { + return new RedisClient(commandExecutor, connectionProvider, commandObjects, + clientConfig.getRedisProtocol(), cache); + } + } + + /** + * Create a new builder for configuring RedisClient instances. + * @return a new {@link RedisClient.Builder} instance + */ + public static Builder builder() { + return new Builder(); + } + + public final Pool getPool() { + return ((PooledConnectionProvider) provider).getPool(); + } + + @Override + public Pipeline pipelined() { + return (Pipeline) super.pipelined(); + } +} diff --git a/src/main/java/redis/clients/jedis/RedisClusterClient.java b/src/main/java/redis/clients/jedis/RedisClusterClient.java new file mode 100644 index 0000000000..af01abdca0 --- /dev/null +++ b/src/main/java/redis/clients/jedis/RedisClusterClient.java @@ -0,0 +1,189 @@ +package redis.clients.jedis; + +import java.time.Duration; +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +import redis.clients.jedis.builders.ClusterClientBuilder; +import redis.clients.jedis.executors.ClusterCommandExecutor; +import redis.clients.jedis.executors.CommandExecutor; +import redis.clients.jedis.providers.ClusterConnectionProvider; +import redis.clients.jedis.csc.Cache; +import redis.clients.jedis.providers.ConnectionProvider; +import redis.clients.jedis.util.JedisClusterCRC16; + +// @formatter:off +/** + * RedisClusterClient provides a high-level, unified interface for interacting with a Redis Cluster. + *

+ * This class is intended as a modern replacement for the deprecated {@code JedisCluster} class. It + * supports all cluster operations and is designed to work seamlessly with the {@link UnifiedJedis} + * API, allowing for consistent usage patterns across standalone, sentinel, and cluster deployments. + *

+ * Usage: + * + *

{@code
+ *   Set clusterNodes = new HashSet<>();
+ *   clusterNodes.add(new HostAndPort("127.0.0.1", 7000));
+ *   RedisClusterClient client = new RedisClusterClient(clusterNodes);
+ *   client.set("key", "value");
+ *   String value = client.get("key");
+ * }
+ *

+ * Migration: Users of {@code JedisCluster} are encouraged to migrate to this class for + * improved API consistency, better resource management, and enhanced support for future Redis + * features. + *

+ * Thread-safety: This client is thread-safe and can be shared across multiple threads. + *

+ * Configuration: Various constructors allow for flexible configuration, including + * authentication and custom timeouts. + */ +// @formatter:on +public class RedisClusterClient extends UnifiedJedis { + + public static final String INIT_NO_ERROR_PROPERTY = "jedis.cluster.initNoError"; + + /** + * Default timeout in milliseconds. + */ + public static final int DEFAULT_TIMEOUT = 2000; + + /** + * Default amount of attempts for executing a command + */ + public static final int DEFAULT_MAX_ATTEMPTS = 5; + + /** + * Creates a RedisClusterClient instance. The provided node is used to make the first contact with + * the cluster. + *

+ * Here, the default timeout of {@value redis.clients.jedis.RedisClusterClient#DEFAULT_TIMEOUT} ms + * is being used with {@value redis.clients.jedis.RedisClusterClient#DEFAULT_MAX_ATTEMPTS} maximum + * attempts. + * @param node Node to first connect to. + */ + public RedisClusterClient(HostAndPort node) { + super( + new ClusterConnectionProvider(Collections.singleton(node), + DefaultJedisClientConfig.builder().timeoutMillis(DEFAULT_TIMEOUT).build()), + DEFAULT_MAX_ATTEMPTS, Duration.ofMillis((long) DEFAULT_TIMEOUT * DEFAULT_MAX_ATTEMPTS)); + } + + /** + * Creates a RedisClusterClient with multiple entry points. + *

+ * Here, the default timeout of {@value redis.clients.jedis.RedisClusterClient#DEFAULT_TIMEOUT} ms + * is being used with {@value redis.clients.jedis.RedisClusterClient#DEFAULT_MAX_ATTEMPTS} maximum + * attempts. + * @param nodes Nodes to connect to. + */ + public RedisClusterClient(Set nodes) { + super( + new ClusterConnectionProvider(nodes, + DefaultJedisClientConfig.builder().timeoutMillis(DEFAULT_TIMEOUT).build()), + DEFAULT_MAX_ATTEMPTS, Duration.ofMillis((long) DEFAULT_TIMEOUT * DEFAULT_MAX_ATTEMPTS)); + } + + public RedisClusterClient(Set nodes, String user, String password) { + super( + new ClusterConnectionProvider(nodes, + DefaultJedisClientConfig.builder().user(user).password(password).build()), + DEFAULT_MAX_ATTEMPTS, + Duration.ofMillis((long) Protocol.DEFAULT_TIMEOUT * DEFAULT_MAX_ATTEMPTS)); + } + + private RedisClusterClient(CommandExecutor commandExecutor, ConnectionProvider connectionProvider, + CommandObjects commandObjects, RedisProtocol redisProtocol, Cache cache) { + super(commandExecutor, connectionProvider, commandObjects, redisProtocol, cache); + } + + /** + * Fluent builder for {@link RedisClusterClient} (Redis Cluster). + *

+ * Obtain an instance via {@link #builder()}. + *

+ */ + public static class Builder extends ClusterClientBuilder { + + @Override + protected RedisClusterClient createClient() { + return new RedisClusterClient(commandExecutor, connectionProvider, commandObjects, + clientConfig.getRedisProtocol(), cache); + } + } + + /** + * Create a new builder for configuring RedisClusterClient instances. + * @return a new {@link RedisClusterClient.Builder} instance + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Returns all nodes that were configured to connect to in key-value pairs ({@link Map}).
+ * Key is the HOST:PORT and the value is the connection pool. + * @return the map of all connections. + */ + public Map getClusterNodes() { + return ((ClusterConnectionProvider) provider).getNodes(); + } + + /** + * Returns the connection for one of the 16,384 slots. + * @param slot the slot to retrieve the connection for. + * @return connection of the provided slot. {@code close()} of this connection must be called + * after use. + */ + public Connection getConnectionFromSlot(int slot) { + return ((ClusterConnectionProvider) provider).getConnectionFromSlot(slot); + } + + // commands + public long spublish(String channel, String message) { + return executeCommand(commandObjects.spublish(channel, message)); + } + + public long spublish(byte[] channel, byte[] message) { + return executeCommand(commandObjects.spublish(channel, message)); + } + + public void ssubscribe(final JedisShardedPubSub jedisPubSub, final String... channels) { + try (Connection connection = getConnectionFromSlot(JedisClusterCRC16.getSlot(channels[0]))) { + jedisPubSub.proceed(connection, channels); + } + } + + public void ssubscribe(BinaryJedisShardedPubSub jedisPubSub, final byte[]... channels) { + try (Connection connection = getConnectionFromSlot(JedisClusterCRC16.getSlot(channels[0]))) { + jedisPubSub.proceed(connection, channels); + } + } + // commands + + @Override + public ClusterPipeline pipelined() { + return new ClusterPipeline((ClusterConnectionProvider) provider, + (ClusterCommandObjects) commandObjects); + } + + /** + * @param doMulti param + * @return nothing + * @throws UnsupportedOperationException + */ + @Override + public AbstractTransaction transaction(boolean doMulti) { + throw new UnsupportedOperationException(); + } + + public final T executeCommandToReplica(CommandObject commandObject) { + if (!(executor instanceof ClusterCommandExecutor)) { + throw new UnsupportedOperationException( + "Support only execute to replica in ClusterCommandExecutor"); + } + return ((ClusterCommandExecutor) executor).executeCommandToReplica(commandObject); + } +} diff --git a/src/main/java/redis/clients/jedis/RedisSentinelClient.java b/src/main/java/redis/clients/jedis/RedisSentinelClient.java new file mode 100644 index 0000000000..1d8207abcf --- /dev/null +++ b/src/main/java/redis/clients/jedis/RedisSentinelClient.java @@ -0,0 +1,76 @@ +package redis.clients.jedis; + +import redis.clients.jedis.builders.SentinelClientBuilder; +import redis.clients.jedis.csc.Cache; + +import redis.clients.jedis.executors.CommandExecutor; +import redis.clients.jedis.providers.ConnectionProvider; +import redis.clients.jedis.providers.SentineledConnectionProvider; + +// @formatter:off +/** + * A high-level client for interacting with Redis Sentinel-managed Redis deployments. + *

+ * {@code RedisSentinelClient} provides robust support for automatic master failover, connection + * management, and command execution in environments where Redis Sentinel is used to monitor and + * manage Redis servers. + *

+ *

+ * Usage: + *

+ * + *
+ * RedisSentinelClient client = RedisSentinelClient.builder().sentinel("localhost", 26379)
+ *     .masterName("mymaster").build();
+ * 
+ *

+ * Relationship to {@code JedisSentineled}:

+ *
    + *
  • {@code RedisSentinelClient} is the recommended replacement for the deprecated + * {@code JedisSentineled} class.
  • + *
  • It offers improved API consistency, better failover handling, and a fluent builder for + * configuration.
  • + *
  • Use {@code RedisSentinelClient} for new codebases and when migrating from + * {@code JedisSentineled}.
  • + *
+ */ + // @formatter:on +public class RedisSentinelClient extends UnifiedJedis { + private RedisSentinelClient(CommandExecutor commandExecutor, + ConnectionProvider connectionProvider, CommandObjects commandObjects, + RedisProtocol redisProtocol, Cache cache) { + super(commandExecutor, connectionProvider, commandObjects, redisProtocol, cache); + } + + /** + * Fluent builder for {@link RedisSentinelClient} (Redis Sentinel). + *

+ * Obtain an instance via {@link #builder()}. + *

+ */ + public static class Builder extends SentinelClientBuilder { + + @Override + protected RedisSentinelClient createClient() { + return new RedisSentinelClient(commandExecutor, connectionProvider, commandObjects, + clientConfig.getRedisProtocol(), cache); + } + } + + /** + * Create a new builder for configuring RedisSentinelClient instances. + * @return a new {@link RedisSentinelClient.Builder} instance + */ + public static Builder builder() { + return new Builder(); + } + + public HostAndPort getCurrentMaster() { + return ((SentineledConnectionProvider) provider).getCurrentMaster(); + } + + @Override + public Pipeline pipelined() { + return (Pipeline) super.pipelined(); + } +} diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index f811fff347..0abb100ae7 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -26,7 +26,6 @@ import redis.clients.jedis.json.JsonSetParams; import redis.clients.jedis.json.Path; import redis.clients.jedis.json.Path2; -import redis.clients.jedis.mcf.MultiDbCommandExecutor; import redis.clients.jedis.params.VAddParams; import redis.clients.jedis.params.VSimParams; import redis.clients.jedis.resps.RawVector; @@ -59,18 +58,34 @@ public class UnifiedJedis implements JedisCommands, JedisBinaryCommands, private JedisBroadcastAndRoundRobinConfig broadcastAndRoundRobinConfig = null; private final Cache cache; + /** + * @deprecated Use {@link RedisClient#RedisClient()} instead. + */ + @Deprecated public UnifiedJedis() { this(new HostAndPort(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT)); } + /** + * @deprecated Use {@link RedisClient#RedisClient(HostAndPort)} instead. + */ + @Deprecated public UnifiedJedis(HostAndPort hostAndPort) { this(new PooledConnectionProvider(hostAndPort), (RedisProtocol) null); } + /** + * @deprecated Use {@link RedisClient#RedisClient(String)} instead. + */ + @Deprecated public UnifiedJedis(final String url) { this(URI.create(url)); } + /** + * @deprecated Use {@link RedisClient#RedisClient(URI)} instead. + */ + @Deprecated public UnifiedJedis(final URI uri) { this(JedisURIHelper.getHostAndPort(uri), DefaultJedisClientConfig.builder() .user(JedisURIHelper.getUser(uri)).password(JedisURIHelper.getPassword(uri)) @@ -89,7 +104,9 @@ public UnifiedJedis(final URI uri) { * * @param uri The URI to connect to * @param config The JedisClientConfig object to use + * @deprecated Use {@link RedisClient#builder()} to configure the client with custom settings. */ + @Deprecated public UnifiedJedis(final URI uri, JedisClientConfig config) { this(JedisURIHelper.getHostAndPort(uri), DefaultJedisClientConfig.builder() .connectionTimeoutMillis(config.getConnectionTimeoutMillis()) @@ -102,20 +119,33 @@ public UnifiedJedis(final URI uri, JedisClientConfig config) { .sslParameters(config.getSslParameters()).hostnameVerifier(config.getHostnameVerifier()).build()); } + /** + * @deprecated Use {@link RedisClient#builder()} to configure the client with custom settings. + */ + @Deprecated public UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig) { this(new PooledConnectionProvider(hostAndPort, clientConfig), clientConfig.getRedisProtocol()); } + /** + * @deprecated Use {@link RedisClient#builder()} to configure the client with client-side caching. + */ @Experimental + @Deprecated public UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig, CacheConfig cacheConfig) { this(hostAndPort, clientConfig, CacheFactory.getCache(cacheConfig)); } + /** + * @deprecated Use {@link RedisClient#builder()} to configure the client with client-side caching. + */ @Experimental + @Deprecated public UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig, Cache cache) { this(new PooledConnectionProvider(hostAndPort, clientConfig, cache), clientConfig.getRedisProtocol(), cache); } + @Deprecated public UnifiedJedis(ConnectionProvider provider) { this(new DefaultCommandExecutor(provider), provider); } @@ -134,7 +164,9 @@ protected UnifiedJedis(ConnectionProvider provider, RedisProtocol protocol, Cach *

* WARNING: Using this constructor means a {@link NullPointerException} will be occurred if * {@link UnifiedJedis#provider} is accessed. + * @deprecated Use {@link RedisClient#builder()} to configure the client with custom settings. */ + @Deprecated public UnifiedJedis(JedisSocketFactory socketFactory) { this(new Connection(socketFactory)); } @@ -144,7 +176,9 @@ public UnifiedJedis(JedisSocketFactory socketFactory) { *

* WARNING: Using this constructor means a {@link NullPointerException} will be occurred if * {@link UnifiedJedis#provider} is accessed. + * @deprecated Use {@link RedisClient#builder()} to configure the client with custom settings. */ + @Deprecated public UnifiedJedis(JedisSocketFactory socketFactory, JedisClientConfig clientConfig) { this(new Connection(socketFactory, clientConfig)); } @@ -154,7 +188,9 @@ public UnifiedJedis(JedisSocketFactory socketFactory, JedisClientConfig clientCo *

* WARNING: Using this constructor means a {@link NullPointerException} will be occurred if * {@link UnifiedJedis#provider} is accessed. + * @deprecated */ + @Deprecated public UnifiedJedis(Connection connection) { this.provider = null; this.executor = new SimpleCommandExecutor(connection); @@ -170,6 +206,9 @@ public UnifiedJedis(Connection connection) { } } + /** + * @deprecated Use {@link RedisClusterClient#builder()} to configure the cluster client. + */ @Deprecated public UnifiedJedis(ClusterConnectionProvider provider, int maxAttempts, Duration maxTotalRetriesDuration) { this(new ClusterCommandExecutor(provider, maxAttempts, maxTotalRetriesDuration, StaticCommandFlagsRegistry.registry()), provider, @@ -190,6 +229,10 @@ protected UnifiedJedis(ClusterConnectionProvider provider, int maxAttempts, Dura new ClusterCommandObjects(), protocol, cache); } + /** + * @deprecated Use {@link RedisClient#builder()} to configure the client with retry settings. + */ + @Deprecated public UnifiedJedis(ConnectionProvider provider, int maxAttempts, Duration maxTotalRetriesDuration) { this(new RetryableCommandExecutor(provider, maxAttempts, maxTotalRetriesDuration), provider); } @@ -199,7 +242,9 @@ public UnifiedJedis(ConnectionProvider provider, int maxAttempts, Duration maxTo *

* WARNING: Using this constructor means a {@link NullPointerException} will be occurred if * {@link UnifiedJedis#provider} is accessed. + * @deprecated Use {@link RedisClient#builder()} to configure the client with custom settings. */ + @Deprecated public UnifiedJedis(CommandExecutor executor) { this(executor, (ConnectionProvider) null); } @@ -208,8 +253,12 @@ private UnifiedJedis(CommandExecutor executor, ConnectionProvider provider) { this(executor, provider, new CommandObjects()); } - // Uses a fetched connection to process protocol. Should be avoided if possible. + /** + * Uses a fetched connection to process protocol. Should be avoided if possible. + * @deprecated + */ @VisibleForTesting + @Deprecated public UnifiedJedis(CommandExecutor executor, ConnectionProvider provider, CommandObjects commandObjects) { this(executor, provider, commandObjects, null, null); if (this.provider != null) { diff --git a/src/main/java/redis/clients/jedis/builders/ClusterClientBuilder.java b/src/main/java/redis/clients/jedis/builders/ClusterClientBuilder.java index fd211a2ae6..8788e94dc5 100644 --- a/src/main/java/redis/clients/jedis/builders/ClusterClientBuilder.java +++ b/src/main/java/redis/clients/jedis/builders/ClusterClientBuilder.java @@ -15,7 +15,7 @@ * configuration, retry settings, and topology refresh configuration. *

*/ -public abstract class ClusterClientBuilder +public abstract class ClusterClientBuilder extends AbstractClientBuilder, C> { // Cluster-specific configuration fields diff --git a/src/main/java/redis/clients/jedis/mcf/PingStrategy.java b/src/main/java/redis/clients/jedis/mcf/PingStrategy.java index 9f9a143596..bf92a0889f 100644 --- a/src/main/java/redis/clients/jedis/mcf/PingStrategy.java +++ b/src/main/java/redis/clients/jedis/mcf/PingStrategy.java @@ -6,7 +6,7 @@ import redis.clients.jedis.Endpoint; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisPooled; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.UnifiedJedis; import redis.clients.jedis.MultiDbConfig.StrategySupplier; @@ -24,7 +24,8 @@ public PingStrategy(HostAndPort hostAndPort, JedisClientConfig jedisClientConfig HealthCheckStrategy.Config config) { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig<>(); poolConfig.setMaxTotal(MAX_HEALTH_CHECK_POOL_SIZE); - this.jedis = new JedisPooled(hostAndPort, jedisClientConfig, poolConfig); + this.jedis = RedisClient.builder().hostAndPort(hostAndPort).clientConfig(jedisClientConfig) + .poolConfig(poolConfig).build(); this.config = config; } diff --git a/src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java b/src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java index 2f2e62dac8..f7b253cda8 100644 --- a/src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java +++ b/src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java @@ -22,7 +22,7 @@ import redis.clients.jedis.exceptions.JedisClusterOperationException; import redis.clients.jedis.exceptions.JedisException; -import static redis.clients.jedis.JedisCluster.INIT_NO_ERROR_PROPERTY; +import static redis.clients.jedis.RedisClusterClient.INIT_NO_ERROR_PROPERTY; public class ClusterConnectionProvider implements ConnectionProvider { diff --git a/src/test/java/io/redis/examples/BitMapsExample.java b/src/test/java/io/redis/examples/BitMapsExample.java index c356d0de72..6124896a8f 100644 --- a/src/test/java/io/redis/examples/BitMapsExample.java +++ b/src/test/java/io/redis/examples/BitMapsExample.java @@ -3,7 +3,7 @@ package io.redis.examples; import org.junit.jupiter.api.Test; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -13,7 +13,7 @@ public class BitMapsExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END // REMOVE_START diff --git a/src/test/java/io/redis/examples/BitfieldExample.java b/src/test/java/io/redis/examples/BitfieldExample.java index 9b3f3b2370..b729f13ffe 100644 --- a/src/test/java/io/redis/examples/BitfieldExample.java +++ b/src/test/java/io/redis/examples/BitfieldExample.java @@ -7,7 +7,7 @@ // REMOVE_END // HIDE_START -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertEquals; // HIDE_END @@ -17,7 +17,7 @@ public class BitfieldExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END //REMOVE_START diff --git a/src/test/java/io/redis/examples/BloomFilterExample.java b/src/test/java/io/redis/examples/BloomFilterExample.java index 77757fa3bc..5012421a63 100644 --- a/src/test/java/io/redis/examples/BloomFilterExample.java +++ b/src/test/java/io/redis/examples/BloomFilterExample.java @@ -3,7 +3,7 @@ // HIDE_START package io.redis.examples; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import org.junit.jupiter.api.Test; import java.util.List; @@ -13,7 +13,7 @@ public class BloomFilterExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END // REMOVE_START diff --git a/src/test/java/io/redis/examples/CMSExample.java b/src/test/java/io/redis/examples/CMSExample.java index ee66412c04..237ec7dd95 100644 --- a/src/test/java/io/redis/examples/CMSExample.java +++ b/src/test/java/io/redis/examples/CMSExample.java @@ -4,7 +4,7 @@ //HIDE_END //REMOVE_START -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import org.junit.jupiter.api.Test; import java.util.HashMap; @@ -17,7 +17,7 @@ public class CMSExample { @Test public void run() { //HIDE_START - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //HIDE_END //REMOVE_START diff --git a/src/test/java/io/redis/examples/CmdsCnxmgmtExample.java b/src/test/java/io/redis/examples/CmdsCnxmgmtExample.java index 17d6876777..07cb379e67 100644 --- a/src/test/java/io/redis/examples/CmdsCnxmgmtExample.java +++ b/src/test/java/io/redis/examples/CmdsCnxmgmtExample.java @@ -20,7 +20,7 @@ public void run() { // REMOVE_START jedis.configSet("requirepass", "temp_pass"); // REMOVE_END - // Note: you must use the `Jedis` class rather than `UnifiedJedis` + // Note: you must use the `Jedis` class rather than `RedisClient` // to access the `auth` commands. String authResult1 = jedis.auth("default", "temp_pass"); System.out.println(authResult1); // >>> OK @@ -34,7 +34,7 @@ public void run() { // REMOVE_START jedis.aclSetUser("test-user", "on", ">strong_password", "+acl"); // REMOVE_END - // Note: you must use the `Jedis` class rather than `UnifiedJedis` + // Note: you must use the `Jedis` class rather than `RedisClient` // to access the `auth` commands. String authResult2 = jedis.auth("test-user", "strong_password"); System.out.println(authResult2); // >>> OK diff --git a/src/test/java/io/redis/examples/CmdsGenericExample.java b/src/test/java/io/redis/examples/CmdsGenericExample.java index f12d5be5e8..9ccad136aa 100644 --- a/src/test/java/io/redis/examples/CmdsGenericExample.java +++ b/src/test/java/io/redis/examples/CmdsGenericExample.java @@ -6,7 +6,7 @@ // REMOVE_END // HIDE_START -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.args.ExpiryOption; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -17,7 +17,7 @@ public class CmdsGenericExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. diff --git a/src/test/java/io/redis/examples/CmdsHashExample.java b/src/test/java/io/redis/examples/CmdsHashExample.java index 064fdf099e..387dbe12c8 100644 --- a/src/test/java/io/redis/examples/CmdsHashExample.java +++ b/src/test/java/io/redis/examples/CmdsHashExample.java @@ -11,7 +11,7 @@ import java.util.Collections; // HIDE_START -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; // HIDE_END import static java.util.stream.Collectors.toList; @@ -23,7 +23,7 @@ public class CmdsHashExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. diff --git a/src/test/java/io/redis/examples/CmdsListExample.java b/src/test/java/io/redis/examples/CmdsListExample.java index a3628196d5..8fe244f3f6 100644 --- a/src/test/java/io/redis/examples/CmdsListExample.java +++ b/src/test/java/io/redis/examples/CmdsListExample.java @@ -7,7 +7,7 @@ import java.util.List; // HIDE_START -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -15,7 +15,7 @@ public class CmdsListExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START jedis.del("mylist"); //REMOVE_END diff --git a/src/test/java/io/redis/examples/CmdsServerMgmtExample.java b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java index 2da0e3756a..07c1782325 100644 --- a/src/test/java/io/redis/examples/CmdsServerMgmtExample.java +++ b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java @@ -8,14 +8,14 @@ import redis.clients.jedis.Jedis; // HIDE_START -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertEquals; public class CmdsServerMgmtExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END // STEP_START flushall @@ -37,7 +37,7 @@ public void run() { // STEP_START info // Note: you must use the `Jedis` class to access the `info` - // command rather than `UnifiedJedis`. + // command rather than `RedisClient`. Jedis jedis2 = new Jedis("redis://localhost:6379"); String infoResult = jedis2.info(); diff --git a/src/test/java/io/redis/examples/CmdsSetExample.java b/src/test/java/io/redis/examples/CmdsSetExample.java index 7e47ccfa76..7c60bfd897 100644 --- a/src/test/java/io/redis/examples/CmdsSetExample.java +++ b/src/test/java/io/redis/examples/CmdsSetExample.java @@ -11,13 +11,13 @@ import java.util.Set; // HIDE_START -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; public class CmdsSetExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START jedis.del("myset"); //REMOVE_END diff --git a/src/test/java/io/redis/examples/CmdsSortedSetExample.java b/src/test/java/io/redis/examples/CmdsSortedSetExample.java index 8412803226..71d636dec5 100644 --- a/src/test/java/io/redis/examples/CmdsSortedSetExample.java +++ b/src/test/java/io/redis/examples/CmdsSortedSetExample.java @@ -8,7 +8,7 @@ import java.util.HashMap; import java.util.Map; import java.util.List; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.params.ZRangeParams; import redis.clients.jedis.resps.Tuple; @@ -19,7 +19,7 @@ public class CmdsSortedSetExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. diff --git a/src/test/java/io/redis/examples/CmdsStringExample.java b/src/test/java/io/redis/examples/CmdsStringExample.java index 4b252f0778..e38dc88d99 100644 --- a/src/test/java/io/redis/examples/CmdsStringExample.java +++ b/src/test/java/io/redis/examples/CmdsStringExample.java @@ -6,7 +6,7 @@ // REMOVE_END // HIDE_START -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertEquals; // HIDE_END @@ -16,7 +16,7 @@ public class CmdsStringExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. diff --git a/src/test/java/io/redis/examples/CuckooFilterExample.java b/src/test/java/io/redis/examples/CuckooFilterExample.java index 26b1be6b7a..0de9b36493 100644 --- a/src/test/java/io/redis/examples/CuckooFilterExample.java +++ b/src/test/java/io/redis/examples/CuckooFilterExample.java @@ -4,7 +4,7 @@ package io.redis.examples; import org.junit.jupiter.api.Test; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -13,7 +13,7 @@ public class CuckooFilterExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END // REMOVE_START diff --git a/src/test/java/io/redis/examples/GeoExample.java b/src/test/java/io/redis/examples/GeoExample.java index d171b92b95..72c0e0f749 100644 --- a/src/test/java/io/redis/examples/GeoExample.java +++ b/src/test/java/io/redis/examples/GeoExample.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; // REMOVE_END import redis.clients.jedis.GeoCoordinate; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.args.GeoUnit; import redis.clients.jedis.resps.GeoRadiusResponse; @@ -18,7 +18,7 @@ public class GeoExample { @Test public void run() { - try (UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379")) { + try (RedisClient jedis = new RedisClient("redis://localhost:6379")) { // REMOVE_START jedis.del("bikes:rentable"); // REMOVE_END diff --git a/src/test/java/io/redis/examples/GeoIndexExample.java b/src/test/java/io/redis/examples/GeoIndexExample.java index 6254eaab7b..8dafe921af 100644 --- a/src/test/java/io/redis/examples/GeoIndexExample.java +++ b/src/test/java/io/redis/examples/GeoIndexExample.java @@ -8,7 +8,7 @@ // HIDE_START import org.json.JSONObject; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.json.Path2; import redis.clients.jedis.search.Document; import redis.clients.jedis.search.FTCreateParams; @@ -27,7 +27,7 @@ public class GeoIndexExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. try { diff --git a/src/test/java/io/redis/examples/HashExample.java b/src/test/java/io/redis/examples/HashExample.java index 7ba473ef97..b53c468111 100644 --- a/src/test/java/io/redis/examples/HashExample.java +++ b/src/test/java/io/redis/examples/HashExample.java @@ -1,7 +1,7 @@ //EXAMPLE: hash_tutorial package io.redis.examples; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import java.util.HashMap; import java.util.List; @@ -16,7 +16,7 @@ public class HashExample { @Test public void run() { - try (UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379")) { + try (RedisClient jedis = new RedisClient("redis://localhost:6379")) { // REMOVE_START jedis.del("bike:1", "bike:1:stats"); // REMOVE_END diff --git a/src/test/java/io/redis/examples/HomeJsonExample.java b/src/test/java/io/redis/examples/HomeJsonExample.java index c9124b2fc2..3d25a1c9fb 100644 --- a/src/test/java/io/redis/examples/HomeJsonExample.java +++ b/src/test/java/io/redis/examples/HomeJsonExample.java @@ -7,7 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; // REMOVE_END // STEP_START import -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.json.Path2; import redis.clients.jedis.search.*; @@ -27,7 +27,7 @@ public class HomeJsonExample { public void run() { // HIDE_END // STEP_START connect - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // STEP_END //REMOVE_START diff --git a/src/test/java/io/redis/examples/HomeProbDtsExample.java b/src/test/java/io/redis/examples/HomeProbDtsExample.java index 4bafa7d561..7b45ca32e0 100644 --- a/src/test/java/io/redis/examples/HomeProbDtsExample.java +++ b/src/test/java/io/redis/examples/HomeProbDtsExample.java @@ -2,7 +2,7 @@ package io.redis.examples; // REMOVE_START import org.junit.jupiter.api.Test; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -15,7 +15,7 @@ public class HomeProbDtsExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // REMOVE_START jedis.del( diff --git a/src/test/java/io/redis/examples/HyperLogLogExample.java b/src/test/java/io/redis/examples/HyperLogLogExample.java index bc3232f6f8..54b907d696 100644 --- a/src/test/java/io/redis/examples/HyperLogLogExample.java +++ b/src/test/java/io/redis/examples/HyperLogLogExample.java @@ -2,7 +2,7 @@ package io.redis.examples; import org.junit.jupiter.api.Test; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -11,7 +11,7 @@ public class HyperLogLogExample { @Test public void run() { // HIDE_START - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END // REMOVE_START diff --git a/src/test/java/io/redis/examples/JsonExample.java b/src/test/java/io/redis/examples/JsonExample.java index 2e4a8c5bdf..ed7ba71037 100644 --- a/src/test/java/io/redis/examples/JsonExample.java +++ b/src/test/java/io/redis/examples/JsonExample.java @@ -8,7 +8,7 @@ // REMOVE_END // HIDE_START -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.json.Path2; import org.json.JSONArray; @@ -21,7 +21,7 @@ public class JsonExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END //REMOVE_START diff --git a/src/test/java/io/redis/examples/ListExample.java b/src/test/java/io/redis/examples/ListExample.java index ac82e6d611..d9be4880e6 100644 --- a/src/test/java/io/redis/examples/ListExample.java +++ b/src/test/java/io/redis/examples/ListExample.java @@ -3,7 +3,7 @@ package io.redis.examples; import org.junit.jupiter.api.Test; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.args.ListDirection; import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -12,7 +12,7 @@ public class ListExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END // REMOVE_START diff --git a/src/test/java/io/redis/examples/PipeTransExample.java b/src/test/java/io/redis/examples/PipeTransExample.java index 71c2d83842..882483595b 100644 --- a/src/test/java/io/redis/examples/PipeTransExample.java +++ b/src/test/java/io/redis/examples/PipeTransExample.java @@ -6,7 +6,7 @@ // REMOVE_END import java.util.List; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.AbstractPipeline; import redis.clients.jedis.AbstractTransaction; import redis.clients.jedis.Response; @@ -17,7 +17,7 @@ public class PipeTransExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // REMOVE_START for (int i = 0; i < 5; i++) { diff --git a/src/test/java/io/redis/examples/QueryAggExample.java b/src/test/java/io/redis/examples/QueryAggExample.java index d6073699a9..90c66a1bd3 100644 --- a/src/test/java/io/redis/examples/QueryAggExample.java +++ b/src/test/java/io/redis/examples/QueryAggExample.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.ArrayList; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.json.Path2; import redis.clients.jedis.search.FTCreateParams; import redis.clients.jedis.search.IndexDataType; @@ -27,7 +27,7 @@ public class QueryAggExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. diff --git a/src/test/java/io/redis/examples/QueryEmExample.java b/src/test/java/io/redis/examples/QueryEmExample.java index 5c866439c6..58b42bf998 100644 --- a/src/test/java/io/redis/examples/QueryEmExample.java +++ b/src/test/java/io/redis/examples/QueryEmExample.java @@ -8,7 +8,7 @@ // HIDE_START import java.util.List; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.json.Path2; import redis.clients.jedis.search.*; import redis.clients.jedis.search.schemafields.*; @@ -21,7 +21,7 @@ public class QueryEmExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. diff --git a/src/test/java/io/redis/examples/QueryFtExample.java b/src/test/java/io/redis/examples/QueryFtExample.java index e15c2a4b0b..3bb1755391 100644 --- a/src/test/java/io/redis/examples/QueryFtExample.java +++ b/src/test/java/io/redis/examples/QueryFtExample.java @@ -6,7 +6,7 @@ // REMOVE_END // HIDE_START import java.util.List; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.search.*; import redis.clients.jedis.search.schemafields.*; import redis.clients.jedis.exceptions.JedisDataException; @@ -20,7 +20,7 @@ public class QueryFtExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. diff --git a/src/test/java/io/redis/examples/QueryGeoExample.java b/src/test/java/io/redis/examples/QueryGeoExample.java index 2fd6334224..4cde2805b0 100644 --- a/src/test/java/io/redis/examples/QueryGeoExample.java +++ b/src/test/java/io/redis/examples/QueryGeoExample.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.stream.Stream; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.search.*; import redis.clients.jedis.search.schemafields.*; import redis.clients.jedis.search.schemafields.GeoShapeField.CoordinateSystem; @@ -25,7 +25,7 @@ public class QueryGeoExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. diff --git a/src/test/java/io/redis/examples/QueryRangeExample.java b/src/test/java/io/redis/examples/QueryRangeExample.java index 4ff9f960bb..849550c017 100644 --- a/src/test/java/io/redis/examples/QueryRangeExample.java +++ b/src/test/java/io/redis/examples/QueryRangeExample.java @@ -11,7 +11,7 @@ import java.util.stream.Stream; // REMOVE_END -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.search.*; import redis.clients.jedis.search.schemafields.*; import redis.clients.jedis.exceptions.JedisDataException; @@ -27,7 +27,7 @@ public class QueryRangeExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //REMOVE_START // Clear any keys here before using them in tests. diff --git a/src/test/java/io/redis/examples/SearchQuickstartExample.java b/src/test/java/io/redis/examples/SearchQuickstartExample.java index 8fbe5d7f32..5171cdecc3 100644 --- a/src/test/java/io/redis/examples/SearchQuickstartExample.java +++ b/src/test/java/io/redis/examples/SearchQuickstartExample.java @@ -36,8 +36,7 @@ public class SearchQuickstartExample { @Test public void run() { // STEP_START connect - // UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); - JedisPooled jedis = new JedisPooled("localhost", 6379); + RedisClient jedis = new RedisClient("localhost", 6379); // STEP_END // REMOVE_START try { diff --git a/src/test/java/io/redis/examples/SetGetExample.java b/src/test/java/io/redis/examples/SetGetExample.java index f75fda040e..dd3e0e6a32 100644 --- a/src/test/java/io/redis/examples/SetGetExample.java +++ b/src/test/java/io/redis/examples/SetGetExample.java @@ -2,7 +2,7 @@ // HIDE_START package io.redis.examples; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; // REMOVE_START import org.junit.jupiter.api.Test; @@ -14,7 +14,7 @@ public class SetGetExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END String status = jedis.set("bike:1", "Process 134"); diff --git a/src/test/java/io/redis/examples/SetsExample.java b/src/test/java/io/redis/examples/SetsExample.java index e3f45ad0d2..8f6acf0b1b 100644 --- a/src/test/java/io/redis/examples/SetsExample.java +++ b/src/test/java/io/redis/examples/SetsExample.java @@ -2,7 +2,7 @@ //HIDE_START package io.redis.examples; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import org.junit.jupiter.api.Test; import java.util.List; import java.util.Set; @@ -15,7 +15,7 @@ public class SetsExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // HIDE_END // REMOVE_START diff --git a/src/test/java/io/redis/examples/SortedSetsExample.java b/src/test/java/io/redis/examples/SortedSetsExample.java index ee7a9af4ac..446b784eef 100644 --- a/src/test/java/io/redis/examples/SortedSetsExample.java +++ b/src/test/java/io/redis/examples/SortedSetsExample.java @@ -2,7 +2,7 @@ //HIDE_START package io.redis.examples; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.resps.Tuple; //HIDE_END @@ -19,7 +19,7 @@ public class SortedSetsExample { @Test public void run() { //HIDE_START - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //HIDE_END //REMOVE_START diff --git a/src/test/java/io/redis/examples/StreamsExample.java b/src/test/java/io/redis/examples/StreamsExample.java index 7fa10b35e4..314e60ef8d 100644 --- a/src/test/java/io/redis/examples/StreamsExample.java +++ b/src/test/java/io/redis/examples/StreamsExample.java @@ -3,7 +3,7 @@ package io.redis.examples; import redis.clients.jedis.StreamEntryID; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; //HIDE_END //REMOVE_START @@ -22,7 +22,7 @@ public class StreamsExample { @Test public void run() { //HIDE_START - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); //HIDE_END //REMOVE_START diff --git a/src/test/java/io/redis/examples/StringExample.java b/src/test/java/io/redis/examples/StringExample.java index d027a3329d..181174de7f 100644 --- a/src/test/java/io/redis/examples/StringExample.java +++ b/src/test/java/io/redis/examples/StringExample.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; //REMOVE_END -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.params.SetParams; import java.util.ArrayList; @@ -18,7 +18,7 @@ public class StringExample { @Test public void run() { - try (UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379")) { + try (RedisClient jedis = new RedisClient("redis://localhost:6379")) { // STEP_START set_get String res1 = jedis.set("bike:1", "Deimos"); diff --git a/src/test/java/io/redis/examples/TDigestExample.java b/src/test/java/io/redis/examples/TDigestExample.java index e6e6b6b2fd..b8000150de 100644 --- a/src/test/java/io/redis/examples/TDigestExample.java +++ b/src/test/java/io/redis/examples/TDigestExample.java @@ -6,7 +6,7 @@ //REMOVE_START import java.util.List; import org.junit.jupiter.api.Test; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertEquals; //REMOVE_END @@ -16,7 +16,7 @@ public class TDigestExample { @Test public void run(){ //HIDE_START - UnifiedJedis jedis = new UnifiedJedis("redis://127.0.0.1:6379"); + RedisClient jedis = new RedisClient("redis://127.0.0.1:6379"); //HIDE_END //REMOVE_START diff --git a/src/test/java/io/redis/examples/TimeSeriesTutorialExample.java b/src/test/java/io/redis/examples/TimeSeriesTutorialExample.java index f40fa8000c..077b092c59 100644 --- a/src/test/java/io/redis/examples/TimeSeriesTutorialExample.java +++ b/src/test/java/io/redis/examples/TimeSeriesTutorialExample.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; // REMOVE_END -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.timeseries.*; import redis.clients.jedis.timeseries.TSElement; @@ -17,7 +17,7 @@ public class TimeSeriesTutorialExample { @Test public void run() { - UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + RedisClient jedis = new RedisClient("redis://localhost:6379"); // REMOVE_START // Clear any keys before using them in tests jedis.del( diff --git a/src/test/java/io/redis/examples/TopKExample.java b/src/test/java/io/redis/examples/TopKExample.java index 34e03aa510..1ffa731f79 100644 --- a/src/test/java/io/redis/examples/TopKExample.java +++ b/src/test/java/io/redis/examples/TopKExample.java @@ -6,7 +6,7 @@ //REMOVE_START import java.util.List; import org.junit.jupiter.api.Test; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; //REMOVE_END public class TopKExample { @@ -14,7 +14,7 @@ public class TopKExample { @Test public void run() { //HIDE_START - UnifiedJedis jedis = new UnifiedJedis("redis://127.0.0.1:6379"); + RedisClient jedis = new RedisClient("redis://127.0.0.1:6379"); //HIDE_END //REMOVE_START diff --git a/src/test/java/io/redis/examples/VectorSetExample.java b/src/test/java/io/redis/examples/VectorSetExample.java index 0b82c6dc78..b29ccbe133 100644 --- a/src/test/java/io/redis/examples/VectorSetExample.java +++ b/src/test/java/io/redis/examples/VectorSetExample.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; // REMOVE_END -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.params.VAddParams; import redis.clients.jedis.params.VSimParams; @@ -15,7 +15,7 @@ public class VectorSetExample { @Test public void run() { - try (UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379")) { + try (RedisClient jedis = new RedisClient("redis://localhost:6379")) { // REMOVE_START jedis.del("points", "quantSetQ8", "quantSetNoQ", "quantSetBin", "setNotReduced", "setReduced"); diff --git a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java index 375efb7d4a..9d1ae42c4c 100644 --- a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java +++ b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java @@ -176,7 +176,7 @@ public void constructorConnectionProvider() { @Test public void clusterPipelined() { - try (JedisCluster cluster = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG); + try (RedisClusterClient cluster = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build(); ClusterPipeline pipeline = cluster.pipelined()) { Response r1 = pipeline.set("key1", "value1"); @@ -199,7 +199,7 @@ public void clusterPipelined() { @Test public void intermediateSync() { - try (JedisCluster cluster = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG); + try (RedisClusterClient cluster = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build(); ClusterPipeline pipeline = cluster.pipelined()) { Response r1 = pipeline.set("key1", "value1"); @@ -226,7 +226,7 @@ public void intermediateSync() { @Test public void intermediateSyncs() { - try (JedisCluster cluster = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG); + try (RedisClusterClient cluster = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build(); ClusterPipeline pipeline = cluster.pipelined()) { Response r1 = pipeline.set("key1", "value1"); @@ -253,7 +253,7 @@ public void intermediateSyncs() { @Test public void pipelineResponse() { - try (JedisCluster jc = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build()) { jc.set("string", "foo"); jc.lpush("list", "foo"); jc.hset("hash", "foo", "bar"); @@ -305,7 +305,7 @@ public void pipelineResponse() { @Test public void pipelineBinarySafeHashCommands() { - try (JedisCluster jc = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build()) { jc.hset("key".getBytes(), "f1".getBytes(), "v111".getBytes()); jc.hset("key".getBytes(), "f22".getBytes(), "v2222".getBytes()); } @@ -970,7 +970,7 @@ public void testEvalNestedListsWithBinary() { public void testEvalsha() { String script = "return 'success!'"; String sha1; - try (JedisCluster jc = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build()) { sha1 = jc.scriptLoad(script, "sampleKey"); assertTrue(jc.scriptExists(sha1, "sampleKey")); } @@ -990,7 +990,7 @@ public void testEvalshaKeyAndArg() { String arg = "3"; String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])"; String sha1; - try (JedisCluster jc = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build()) { sha1 = jc.scriptLoad(script, key); assertTrue(jc.scriptExists(sha1, key)); } @@ -1017,7 +1017,7 @@ public void testEvalshaKeyAndArgWithBinary() { String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])"; byte[] bScript = SafeEncoder.encode(script); byte[] bSha1; - try (JedisCluster jc = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build()) { bSha1 = jc.scriptLoad(bScript, bKey); assertTrue(jc.scriptExists(bSha1, bKey)); } @@ -1039,7 +1039,7 @@ public void testEvalshaKeyAndArgWithBinary() { @Test public void spublishInPipeline() { - try (JedisCluster jedis = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + try (RedisClusterClient jedis = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build()) { ClusterPipeline pipelined = jedis.pipelined(); Response p1 = pipelined.publish("foo", "bar"); Response p2 = pipelined.publish("foo".getBytes(), "bar".getBytes()); @@ -1051,7 +1051,7 @@ public void spublishInPipeline() { @Test public void simple() { // TODO: move into 'redis.clients.jedis.commands.unified.cluster' package - try (JedisCluster jedis = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + try (RedisClusterClient jedis = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build()) { final int count = 10; int totalCount = 0; for (int i = 0; i < count; i++) { @@ -1084,7 +1084,7 @@ public void simple() { // TODO: move into 'redis.clients.jedis.commands.unified. @Test public void transaction() { - try (JedisCluster cluster = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + try (RedisClusterClient cluster = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build()) { assertThrows(UnsupportedOperationException.class, () -> cluster.multi()); } } @@ -1095,7 +1095,7 @@ public void multiple() { final int maxTotal = 100; ConnectionPoolConfig poolConfig = new ConnectionPoolConfig(); poolConfig.setMaxTotal(maxTotal); - try (JedisCluster cluster = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG, 5, poolConfig)) { + try (RedisClusterClient cluster = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).maxAttempts(5).poolConfig(poolConfig).build()) { for (int i = 0; i < maxTotal; i++) { assertThreadsCount(); String s = Integer.toString(i); @@ -1110,7 +1110,7 @@ public void multiple() { @Test public void testPipelineKeysAtSameNode() { - try (JedisCluster cluster = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + try (RedisClusterClient cluster = RedisClusterClient.builder().nodes(nodes).clientConfig(DEFAULT_CLIENT_CONFIG).build()) { // test simple key cluster.set("foo", "bar"); diff --git a/src/test/java/redis/clients/jedis/JedisPooledTest.java b/src/test/java/redis/clients/jedis/RedisClientTest.java similarity index 89% rename from src/test/java/redis/clients/jedis/JedisPooledTest.java rename to src/test/java/redis/clients/jedis/RedisClientTest.java index a7dead0b01..fa75e06cce 100644 --- a/src/test/java/redis/clients/jedis/JedisPooledTest.java +++ b/src/test/java/redis/clients/jedis/RedisClientTest.java @@ -22,7 +22,7 @@ import redis.clients.jedis.exceptions.JedisException; @Tag("integration") -public class JedisPooledTest { +public class RedisClientTest { private static final EndpointConfig endpointStandalone7 = HostAndPorts.getRedisEndpoint( "standalone7-with-lfu-policy"); @@ -31,7 +31,7 @@ public class JedisPooledTest { @Test public void checkCloseableConnections() { - JedisPooled pool = JedisPooled.builder() + RedisClient pool = RedisClient.builder() .hostAndPort(endpointStandalone7.getHost(), endpointStandalone7.getPort()) .clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000).build()).build(); pool.set("foo", "bar"); @@ -42,7 +42,7 @@ public void checkCloseableConnections() { @Test public void checkResourceWithConfig() { - try (JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort()) + try (RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort()) .clientConfig(DefaultJedisClientConfig.builder().socketTimeoutMillis(5000).build()) .build()) { @@ -59,7 +59,7 @@ public void checkPoolOverflow() { config.setMaxTotal(1); config.setBlockWhenExhausted(false); try ( - JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort()) + RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort()) .poolConfig(config).build(); Connection jedis = pool.getPool().getResource()) { assertThrows(JedisException.class, () -> pool.getPool().getResource()); @@ -74,7 +74,7 @@ public void startWithUrlString() { j.set("foo", "bar"); } - try (JedisPooled pool = JedisPooled.builder() + try (RedisClient pool = RedisClient.builder() .fromURI(endpointStandalone1.getURIBuilder() .credentials("", endpointStandalone1.getPassword()).path("/2").build().toString()) .build()) { @@ -90,7 +90,7 @@ public void startWithUrl() throws URISyntaxException { j.set("foo", "bar"); } - try (JedisPooled pool = JedisPooled.builder().fromURI(endpointStandalone1.getURIBuilder() + try (RedisClient pool = RedisClient.builder().fromURI(endpointStandalone1.getURIBuilder() .credentials("", endpointStandalone1.getPassword()).path("/2").build()).build()) { assertEquals("bar", pool.get("foo")); } @@ -99,19 +99,19 @@ public void startWithUrl() throws URISyntaxException { @Test public void shouldThrowExceptionForInvalidURI() { assertThrows(Exception.class, - () -> JedisPooled.builder().fromURI(new URI("localhost:6380")).build()); + () -> RedisClient.builder().fromURI(new URI("localhost:6380")).build()); } @Test public void allowUrlWithNoDBAndNoPassword() throws URISyntaxException { - JedisPooled.builder().fromURI(endpointStandalone1.getURI().toString()).build().close(); - JedisPooled.builder().fromURI(endpointStandalone1.getURI()).build().close(); + RedisClient.builder().fromURI(endpointStandalone1.getURI().toString()).build().close(); + RedisClient.builder().fromURI(endpointStandalone1.getURI()).build().close(); } @Test public void customClientName() { try ( - JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort()) + RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort()) .clientConfig( DefaultJedisClientConfig.builder().clientName("my_shiny_client_name").build()) .build(); @@ -123,7 +123,7 @@ public void customClientName() { @Test public void invalidClientName() { try ( - JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort()) + RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort()) .clientConfig( DefaultJedisClientConfig.builder().clientName("invalid client name").build()) .build(); @@ -137,7 +137,7 @@ public void invalidClientName() { @Test public void getNumActiveWhenPoolIsClosed() { - JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone7.getHostAndPort()) + RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone7.getHostAndPort()) .build(); try (Connection j = pool.getPool().getResource()) { @@ -150,7 +150,7 @@ public void getNumActiveWhenPoolIsClosed() { @Test public void getNumActiveReturnsTheCorrectNumber() { - try (JedisPooled pool = JedisPooled.builder() + try (RedisClient pool = RedisClient.builder() .hostAndPort(endpointStandalone7.getHost(), endpointStandalone7.getPort()) .clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000).build()) .poolConfig(new ConnectionPoolConfig()).build()) { @@ -171,7 +171,7 @@ public void getNumActiveReturnsTheCorrectNumber() { @Test public void closeResourceTwice() { - try (JedisPooled pool = JedisPooled.builder() + try (RedisClient pool = RedisClient.builder() .hostAndPort(endpointStandalone7.getHost(), endpointStandalone7.getPort()) .clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000).build()) .poolConfig(new ConnectionPoolConfig()).build()) { @@ -184,7 +184,7 @@ public void closeResourceTwice() { @Test public void closeBrokenResourceTwice() { - try (JedisPooled pool = JedisPooled.builder() + try (RedisClient pool = RedisClient.builder() .hostAndPort(endpointStandalone7.getHost(), endpointStandalone7.getPort()) .clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000).build()) .poolConfig(new ConnectionPoolConfig()).build()) { @@ -204,10 +204,10 @@ public void closeBrokenResourceTwice() { @Test public void testResetValidCredentials() { - DefaultRedisCredentialsProvider credentialsProvider = + DefaultRedisCredentialsProvider credentialsProvider = new DefaultRedisCredentialsProvider(new DefaultRedisCredentials(null, "bad password")); - try (JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone1.getHostAndPort()) + try (RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone1.getHostAndPort()) .clientConfig( DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider).build()) .build()) { @@ -269,7 +269,7 @@ public void cleanUp() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig<>(); poolConfig.setMaxTotal(1); poolConfig.setTestOnBorrow(true); - try (JedisPooled pool = JedisPooled.builder().hostAndPort(endpointStandalone1.getHostAndPort()) + try (RedisClient pool = RedisClient.builder().hostAndPort(endpointStandalone1.getHostAndPort()) .clientConfig( DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider).build()) .poolConfig(poolConfig).build()) { diff --git a/src/test/java/redis/clients/jedis/JedisClusterTest.java b/src/test/java/redis/clients/jedis/RedisClusterClientTest.java similarity index 70% rename from src/test/java/redis/clients/jedis/JedisClusterTest.java rename to src/test/java/redis/clients/jedis/RedisClusterClientTest.java index 0325384664..90db4f456f 100644 --- a/src/test/java/redis/clients/jedis/JedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/RedisClusterClientTest.java @@ -42,7 +42,7 @@ import redis.clients.jedis.util.Pool; @Tag("integration") -public class JedisClusterTest extends JedisClusterTestBase { +public class RedisClusterClientTest extends RedisClusterClientTestBase { private static final int DEFAULT_TIMEOUT = 2000; //sec private static final int DEFAULT_REDIRECTIONS = 5; @@ -80,13 +80,29 @@ public void testDiscoverNodesAutomatically() { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals(3, jc.getClusterNodes().size()); } - try (JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379), DEFAULT_TIMEOUT, - DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc2 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 7379))) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals(3, jc2.getClusterNodes().size()); } } @@ -95,13 +111,21 @@ public void testDiscoverNodesAutomatically() { public void testDiscoverNodesAutomaticallyWithSocketConfig() { HostAndPort hp = new HostAndPort("127.0.0.1", 7379); - try (JedisCluster jc = new JedisCluster(hp, DEFAULT_CLIENT_CONFIG, DEFAULT_REDIRECTIONS, - DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hp)) + .clientConfig(DEFAULT_CLIENT_CONFIG) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals(3, jc.getClusterNodes().size()); } - try (JedisCluster jc = new JedisCluster(Collections.singleton(hp), DEFAULT_CLIENT_CONFIG, - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hp)) + .clientConfig(DEFAULT_CLIENT_CONFIG) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals(3, jc.getClusterNodes().size()); } } @@ -112,8 +136,17 @@ public void testSetClientName() { jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); String clientName = "myAppName"; - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", clientName, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .clientName(clientName) + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { for (Pool pool : jc.getClusterNodes().values()) { try (Jedis jedis = new Jedis(pool.getResource())) { assertEquals(clientName, jedis.clientGetname()); @@ -126,9 +159,12 @@ public void testSetClientName() { public void testSetClientNameWithConfig() { HostAndPort hp = new HostAndPort("127.0.0.1", 7379); String clientName = "config-pattern-app"; - try (JedisCluster jc = new JedisCluster(Collections.singleton(hp), - DefaultJedisClientConfig.builder().password("cluster").clientName(clientName).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hp)) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").clientName(clientName).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.getClusterNodes().values().forEach(pool -> { try (Jedis jedis = new Jedis(pool.getResource())) { assertEquals(clientName, jedis.clientGetname()); @@ -142,16 +178,32 @@ public void testCalculateConnectionPerSlot() { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.set("foo", "bar"); jc.set("test", "test"); assertEquals("bar", node3.get("foo")); assertEquals("test", node2.get("test")); } - try (JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379), DEFAULT_TIMEOUT, - DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc2 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 7379))) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc2.set("foo", "bar"); jc2.set("test", "test"); assertEquals("bar", node3.get("foo")); @@ -205,8 +257,12 @@ public void testReadFromReplicas() throws Exception { DefaultJedisClientConfig READ_REPLICAS_CLIENT_CONFIG = DefaultJedisClientConfig.builder() .password("cluster").readOnlyForRedisClusterReplicas().build(); ClusterCommandObjects commandObjects = new ClusterCommandObjects(); - try (JedisCluster jedisCluster = new JedisCluster(nodeInfo1, READ_REPLICAS_CLIENT_CONFIG, - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jedisCluster = RedisClusterClient.builder() + .nodes(Collections.singleton(nodeInfo1)) + .clientConfig(READ_REPLICAS_CLIENT_CONFIG) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals("OK", jedisCluster.set("test", "read-from-replicas")); assertEquals("read-from-replicas", jedisCluster.executeCommandToReplica(commandObjects.get("test"))); @@ -224,8 +280,16 @@ public void testReadFromReplicas() throws Exception { public void testMigrate() { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(nodeInfo1); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes()); String node2Id = JedisClusterTestUtil.getNodeId(node2.clusterNodes()); node3.clusterSetSlotMigrating(15363, node2Id); @@ -274,8 +338,16 @@ public void testMigrate() { public void testMigrateToNewNode() throws InterruptedException { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(nodeInfo1); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { node3.clusterMeet(LOCAL_IP, nodeInfo4.getPort()); String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes()); @@ -335,8 +407,16 @@ public void testRecalculateSlotsWhenMoved() throws InterruptedException { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { int slot51 = JedisClusterCRC16.getSlot("51"); node2.clusterDelSlots(slot51); node3.clusterDelSlots(slot51); @@ -353,8 +433,16 @@ public void testAskResponse() { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { int slot51 = JedisClusterCRC16.getSlot("51"); node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes())); node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes())); @@ -366,8 +454,12 @@ public void testAskResponse() { @Test public void testAskResponseWithConfig() { HostAndPort hp = new HostAndPort("127.0.0.1", 7379); - try (JedisCluster jc = new JedisCluster(Collections.singleton(hp), DEFAULT_CLIENT_CONFIG, - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hp)) + .clientConfig(DEFAULT_CLIENT_CONFIG) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { int slot51 = JedisClusterCRC16.getSlot("51"); node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes())); node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes())); @@ -382,8 +474,16 @@ public void testRedisClusterMaxRedirections() { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); assertThrows(JedisClusterOperationException.class,()-> { - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { int slot51 = JedisClusterCRC16.getSlot("51"); // This will cause an infinite redirection loop node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes())); @@ -396,8 +496,12 @@ public void testRedisClusterMaxRedirections() { @Test public void testRedisClusterMaxRedirectionsWithConfig() { HostAndPort hp = new HostAndPort("127.0.0.1", 7379); - try (JedisCluster jc = new JedisCluster(Collections.singleton(hp), DEFAULT_CLIENT_CONFIG, - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hp)) + .clientConfig(DEFAULT_CLIENT_CONFIG) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { int slot51 = JedisClusterCRC16.getSlot("51"); // This will cause an infinite redirection loop node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes())); @@ -467,8 +571,16 @@ public void testClusterCountKeysInSlot() { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort())); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { int count = 5; for (int index = 0; index < count; index++) { @@ -486,8 +598,16 @@ public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified() Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort())); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { int slot51 = JedisClusterCRC16.getSlot("51"); jc.set("51", "foo"); @@ -512,8 +632,16 @@ public void testIfPoolConfigAppliesToClusterPools() { config.setMaxWait(Duration.ofMillis(DEFAULT_TIMEOUT)); Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", config)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(config) + .build()) { assertThrows(JedisException.class, ()->jc.set("52", "poolTestValue")); } } @@ -523,8 +651,16 @@ public void testCloseable() throws IOException { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort())); - JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG); + RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build(); jc.set("51", "foo"); jc.close(); @@ -534,8 +670,12 @@ public void testCloseable() throws IOException { @Test public void testCloseableWithConfig() { HostAndPort hp = nodeInfo1; - try (JedisCluster jc = new JedisCluster(hp, DEFAULT_CLIENT_CONFIG, DEFAULT_REDIRECTIONS, - DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hp)) + .clientConfig(DEFAULT_CLIENT_CONFIG) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.set("51", "foo"); jc.close(); @@ -548,8 +688,16 @@ public void testJedisClusterTimeout() { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort())); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, 4000, 4000, DEFAULT_REDIRECTIONS, - "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(4000) + .socketTimeoutMillis(4000) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { for (Pool pool : jc.getClusterNodes().values()) { try (Connection conn = pool.getResource()) { @@ -562,9 +710,13 @@ public void testJedisClusterTimeout() { @Test public void testJedisClusterTimeoutWithConfig() { HostAndPort hp = nodeInfo1; - try (JedisCluster jc = new JedisCluster(hp, DefaultJedisClientConfig.builder() - .connectionTimeoutMillis(4000).socketTimeoutMillis(4000).password("cluster").build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hp)) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(4000).socketTimeoutMillis(4000).password("cluster").build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.getClusterNodes().values().forEach(pool -> { try (Connection conn = pool.getResource()) { @@ -579,8 +731,16 @@ public void testJedisClusterRunsWithMultithreaded() throws InterruptedException, ExecutionException, IOException { Set jedisClusterNode = new HashSet<>(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - final JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG); + final RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build(); jc.set("foo", "bar"); ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 0, TimeUnit.SECONDS, @@ -612,8 +772,16 @@ public void testReturnConnectionOnJedisConnectionException() throws InterruptedE jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); ConnectionPoolConfig config = new ConnectionPoolConfig(); config.setMaxTotal(1); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", config)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(config) + .build()) { try (Connection c = jc.getClusterNodes().get("127.0.0.1:7380").getResource()) { Jedis j = new Jedis(c); @@ -632,8 +800,16 @@ public void testReturnConnectionOnRedirection() { jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); ConnectionPoolConfig config = new ConnectionPoolConfig(); config.setMaxTotal(1); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", config)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(config) + .build()) { // This will cause an infinite redirection between node 2 and 3 node3.clusterSetSlotMigrating(15363, JedisClusterTestUtil.getNodeId(node2.clusterNodes())); @@ -651,8 +827,16 @@ public void testLocalhostNodeNotAddedWhen127Present() { ConnectionPoolConfig config = new ConnectionPoolConfig(); config.setMaxTotal(1); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", config)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(config) + .build()) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(localhost))); @@ -667,8 +851,16 @@ public void testInvalidStartNodeNotAdded() { jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); ConnectionPoolConfig config = new ConnectionPoolConfig(); config.setMaxTotal(1); - try (JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, - DEFAULT_REDIRECTIONS, "cluster", config)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(config) + .build()) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(invalidHost))); @@ -697,8 +889,16 @@ public void clusterRefreshNodes() throws Exception { jedisClusterNode.add(nodeInfo2); jedisClusterNode.add(nodeInfo3); - try (JedisCluster cluster = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, - DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient cluster = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(DEFAULT_TIMEOUT) + .socketTimeoutMillis(DEFAULT_TIMEOUT) + .password("cluster") + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals(3, cluster.getClusterNodes().size()); cleanUp(); // cleanup and add node4 @@ -756,8 +956,14 @@ public void clusterPeriodTopologyRefreshTest() throws Exception { // we set topologyRefreshPeriod is 1s Duration topologyRefreshPeriod = Duration.ofSeconds(1); - try (JedisCluster cluster = new JedisCluster(jedisClusterNode, DEFAULT_CLIENT_CONFIG, DEFAULT_POOL_CONFIG, - topologyRefreshPeriod, DEFAULT_REDIRECTIONS, Duration.ofSeconds(10))) { + try (RedisClusterClient cluster = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DEFAULT_CLIENT_CONFIG) + .poolConfig(DEFAULT_POOL_CONFIG) + .topologyRefreshPeriod(topologyRefreshPeriod) + .maxAttempts(DEFAULT_REDIRECTIONS) + .maxTotalRetriesDuration(Duration.ofSeconds(10)) + .build()) { assertEquals(3, cluster.getClusterNodes().size()); cleanUp(); // cleanup and add node4 diff --git a/src/test/java/redis/clients/jedis/JedisClusterTestBase.java b/src/test/java/redis/clients/jedis/RedisClusterClientTestBase.java similarity index 98% rename from src/test/java/redis/clients/jedis/JedisClusterTestBase.java rename to src/test/java/redis/clients/jedis/RedisClusterClientTestBase.java index 542b496fb2..7397502ae8 100644 --- a/src/test/java/redis/clients/jedis/JedisClusterTestBase.java +++ b/src/test/java/redis/clients/jedis/RedisClusterClientTestBase.java @@ -12,7 +12,7 @@ import redis.clients.jedis.util.JedisClusterTestUtil; @Tag("integration") -public abstract class JedisClusterTestBase { +public abstract class RedisClusterClientTestBase { protected static Jedis node1; protected static Jedis node2; diff --git a/src/test/java/redis/clients/jedis/SSLACLJedisClusterTest.java b/src/test/java/redis/clients/jedis/SSLACLRedisClusterClientTest.java similarity index 65% rename from src/test/java/redis/clients/jedis/SSLACLJedisClusterTest.java rename to src/test/java/redis/clients/jedis/SSLACLRedisClusterClientTest.java index 723c43a317..54ba5efc71 100644 --- a/src/test/java/redis/clients/jedis/SSLACLJedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/SSLACLRedisClusterClientTest.java @@ -27,7 +27,7 @@ @SinceRedisVersion(value = "7.0.0", message = "Redis 6.2.x returns non-tls port in CLUSTER SLOTS command. Enable for 6.2.x after tests are fixed.") @Tag("integration") -public class SSLACLJedisClusterTest extends JedisClusterTestBase { +public class SSLACLRedisClusterClientTest extends RedisClusterClientTestBase { private static final int DEFAULT_REDIRECTIONS = 5; private static final ConnectionPoolConfig DEFAULT_POOL_CONFIG = new ConnectionPoolConfig(); @@ -54,7 +54,7 @@ public class SSLACLJedisClusterTest extends JedisClusterTestBase { return new HostAndPort(hostAndPort.getHost(), hostAndPort.getPort() /* + tlsPortOffset */); }; - private static final String trustStoreName = SSLACLJedisClusterTest.class.getSimpleName(); + private static final String trustStoreName = SSLACLRedisClusterClientTest.class.getSimpleName(); @BeforeAll public static void prepare() { @@ -75,8 +75,12 @@ public void testSSLDiscoverNodesAutomatically() { .user("default").password("cluster").ssl(true) .hostAndPortMapper(hostAndPortMap).build(); - try (JedisCluster jc = new JedisCluster(Collections.singleton(new HostAndPort("localhost", 8379)), - config, DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(config) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); @@ -97,8 +101,12 @@ public void testSSLDiscoverNodesAutomatically() { jc.get("foo"); } - try (JedisCluster jc2 = new JedisCluster(new HostAndPort("localhost", 8379), - config, DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc2 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(config) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc2.getClusterNodes(); assertEquals(3, clusterNodes.size()); assertTrue(clusterNodes.containsKey("127.0.0.1:8379")); @@ -110,9 +118,12 @@ public void testSSLDiscoverNodesAutomatically() { @Test public void testSSLWithoutPortMap() { - try (JedisCluster jc = new JedisCluster(Collections.singleton(new HostAndPort("localhost", 8379)), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); /** @@ -134,10 +145,13 @@ public void testSSLWithoutPortMap() { @Test public void connectByIpAddress() { - try (JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 8379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) - .hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) + .hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); } } @@ -147,10 +161,13 @@ public void connectToNodesFailsWithSSLParametersAndNoHostMapping() { final SSLParameters sslParameters = new SSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) - .sslParameters(sslParameters).hostAndPortMapper(portMap).build(), DEFAULT_REDIRECTIONS, - DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) + .sslParameters(sslParameters).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); fail("It should fail after all cluster attempts."); // } catch (JedisClusterMaxAttemptsException e) { @@ -166,10 +183,13 @@ public void connectToNodesSucceedsWithSSLParametersAndHostMapping() { final SSLParameters sslParameters = new SSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) - .sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) + .sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); } } @@ -179,10 +199,13 @@ public void connectByIpAddressFailsWithSSLParameters() { final SSLParameters sslParameters = new SSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); - try (JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 8379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) - .sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) + .sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { // jc.get("key"); // Assert.fail("There should be no reachable node in cluster."); //// } catch (JedisNoReachableClusterNodeException e) { @@ -197,10 +220,13 @@ public void connectWithCustomHostNameVerifier() { HostnameVerifier hostnameVerifier = new TlsUtil.BasicHostnameVerifier(); HostnameVerifier localhostVerifier = new TlsUtil.LocalhostVerifier(); - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) - .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) + .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); fail("It should fail after all cluster attempts."); // } catch (JedisClusterMaxAttemptsException e) { @@ -210,10 +236,13 @@ public void connectWithCustomHostNameVerifier() { assertEquals("No more cluster attempts left.", e.getMessage()); } - try (JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 8379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) - .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc2 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) + .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { // jc2.get("key"); // Assert.fail("There should be no reachable node in cluster."); //// } catch (JedisNoReachableClusterNodeException e) { @@ -224,31 +253,40 @@ public void connectWithCustomHostNameVerifier() { assertEquals("Could not initialize cluster slots cache.", e.getMessage()); } - try (JedisCluster jc3 = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) - .hostnameVerifier(localhostVerifier).hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc3 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) + .hostnameVerifier(localhostVerifier).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc3.get("foo"); } } @Test public void connectWithCustomSocketFactory() { - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) .sslSocketFactory(sslSocketFactoryForEnv(Paths.get("cluster-unbound/work/tls"))) - .hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + .hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals(3, jc.getClusterNodes().size()); } } @Test public void connectWithEmptyTrustStore() throws Exception { - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) - .sslSocketFactory(createTrustNoOneSslSocketFactory()).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(true) + .sslSocketFactory(createTrustNoOneSslSocketFactory()).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { // jc.get("key"); // Assert.fail("There should be no reachable node in cluster."); //// } catch (JedisNoReachableClusterNodeException e) { @@ -262,9 +300,13 @@ public void connectWithEmptyTrustStore() throws Exception { public void defaultHostAndPortUsedIfMapReturnsNull() { HostAndPortMapper nullHostAndPortMap = (HostAndPort hostAndPort) -> null; - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 7379), - DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(false) - .hostAndPortMapper(nullHostAndPortMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 7379))) + .clientConfig(DefaultJedisClientConfig.builder().user("default").password("cluster").ssl(false) + .hostAndPortMapper(nullHostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); assertTrue(clusterNodes.containsKey("127.0.0.1:7379")); diff --git a/src/test/java/redis/clients/jedis/SSLOptionsJedisPooledTest.java b/src/test/java/redis/clients/jedis/SSLOptionsRedisClientTest.java similarity index 68% rename from src/test/java/redis/clients/jedis/SSLOptionsJedisPooledTest.java rename to src/test/java/redis/clients/jedis/SSLOptionsRedisClientTest.java index 6cb5ee0e58..29f543d224 100644 --- a/src/test/java/redis/clients/jedis/SSLOptionsJedisPooledTest.java +++ b/src/test/java/redis/clients/jedis/SSLOptionsRedisClientTest.java @@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @Tag("integration") -public class SSLOptionsJedisPooledTest { +public class SSLOptionsRedisClientTest { protected static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0-tls"); @@ -31,48 +31,56 @@ public static void prepare() { @Test public void connectWithClientConfig() { - try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), - endpoint.getClientConfigBuilder() + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(endpoint.getClientConfigBuilder() .sslOptions(SslOptions.builder() .truststore(trustStorePath.toFile()) .trustStoreType("jceks") - .build()).build())) { + .build()).build()) + .build()) { assertEquals("PONG", jedis.ping()); } } @Test public void connectWithSslInsecure() { - try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), - endpoint.getClientConfigBuilder() + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(endpoint.getClientConfigBuilder() .sslOptions(SslOptions.builder() .sslVerifyMode(SslVerifyMode.INSECURE) - .build()).build())) { + .build()).build()) + .build()) { assertEquals("PONG", jedis.ping()); } } @Test public void connectWithSslContextProtocol() { - try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), - endpoint.getClientConfigBuilder() + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(endpoint.getClientConfigBuilder() .sslOptions(SslOptions.builder() .sslProtocol("SSL") .truststore(trustStorePath.toFile()) .trustStoreType("jceks") - .build()).build())) { + .build()).build()) + .build()) { assertEquals("PONG", jedis.ping()); } } @Test public void connectWithAcl() { - try (JedisPooled jedis = new JedisPooled(aclEndpoint.getHostAndPort(), - aclEndpoint.getClientConfigBuilder() + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(aclEndpoint.getHostAndPort()) + .clientConfig(aclEndpoint.getClientConfigBuilder() .sslOptions(SslOptions.builder() .truststore(trustStorePath.toFile()) .trustStoreType("jceks") - .build()).build())) { + .build()).build()) + .build()) { assertEquals("PONG", jedis.ping()); } } diff --git a/src/test/java/redis/clients/jedis/SSLOptionsJedisClusterTest.java b/src/test/java/redis/clients/jedis/SSLOptionsRedisClusterClientTest.java similarity index 68% rename from src/test/java/redis/clients/jedis/SSLOptionsJedisClusterTest.java rename to src/test/java/redis/clients/jedis/SSLOptionsRedisClusterClientTest.java index 34807d6c99..483d9bfcac 100644 --- a/src/test/java/redis/clients/jedis/SSLOptionsJedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/SSLOptionsRedisClusterClientTest.java @@ -24,7 +24,7 @@ @SinceRedisVersion(value = "7.0.0", message = "Redis 6.2.x returns non-tls port in CLUSTER SLOTS command. Enable for 6.2.x after test is fixed.") @Tag("integration") -public class SSLOptionsJedisClusterTest extends JedisClusterTestBase { +public class SSLOptionsRedisClusterClientTest extends RedisClusterClientTestBase { private static final int DEFAULT_REDIRECTIONS = 5; private static final ConnectionPoolConfig DEFAULT_POOL_CONFIG = new ConnectionPoolConfig(); @@ -46,7 +46,7 @@ public class SSLOptionsJedisClusterTest extends JedisClusterTestBase { return new HostAndPort(hostAndPort.getHost(), hostAndPort.getPort()); }; - private static final String trustStoreName = SSLOptionsJedisClusterTest.class.getSimpleName(); + private static final String trustStoreName = SSLOptionsRedisClusterClientTest.class.getSimpleName(); private static Path trustStorePath; @BeforeAll @@ -57,13 +57,16 @@ public static void prepare() { @Test public void testSSLDiscoverNodesAutomatically() { - try (JedisCluster jc2 = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster") + try (RedisClusterClient jc2 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster") .sslOptions(SslOptions.builder() .truststore(trustStorePath.toFile()) .trustStoreType("jceks").build()) - .hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + .hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc2.getClusterNodes(); assertEquals(3, clusterNodes.size()); /* @@ -85,13 +88,17 @@ public void testSSLDiscoverNodesAutomatically() { @Test public void testSSLWithoutPortMap() { - try (JedisCluster jc = new JedisCluster(Collections.singleton(new HostAndPort("localhost", 8379)), - DefaultJedisClientConfig.builder().password("cluster") + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster") .sslOptions(SslOptions.builder() .truststore(trustStorePath.toFile()) .trustStoreType("jceks") .sslVerifyMode(SslVerifyMode.CA).build()) - .build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + .build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); /** @@ -112,13 +119,16 @@ public void testSSLWithoutPortMap() { @Test public void connectByIpAddress() { - try (JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 8379), - DefaultJedisClientConfig.builder().password("cluster") + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster") .sslOptions(SslOptions.builder() .truststore(trustStorePath.toFile()) .trustStoreType("jceks").build()) - .hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + .hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); } } @@ -128,14 +138,17 @@ public void connectToNodesFailsWithSSLParametersAndNoHostMapping() { final SSLParameters sslParameters = new SSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster") + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster") .sslOptions(SslOptions.builder() .sslParameters(sslParameters) .truststore(trustStorePath.toFile()) .trustStoreType("jceks").build()) - .hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + .hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); fail("It should fail after all cluster attempts."); } catch (JedisClusterOperationException e) { @@ -150,14 +163,17 @@ public void connectToNodesSucceedsWithSSLParametersAndHostMapping() { final SSLParameters sslParameters = new SSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster") + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster") .sslOptions(SslOptions.builder() .sslParameters(sslParameters) .truststore(trustStorePath.toFile()) .trustStoreType("jceks").build()) - .hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + .hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); } } @@ -167,14 +183,17 @@ public void connectByIpAddressFailsWithSSLParameters() { final SSLParameters sslParameters = new SSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); - try (JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 8379), - DefaultJedisClientConfig.builder().password("cluster") + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster") .sslOptions(SslOptions.builder() .sslParameters(sslParameters) .truststore(trustStorePath.toFile()) .trustStoreType("jceks").build()) - .hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + .hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { } catch (JedisClusterOperationException e) { assertEquals("Could not initialize cluster slots cache.", e.getMessage()); } @@ -190,10 +209,13 @@ public void connectWithCustomHostNameVerifier() { .trustStoreType("jceks") .sslVerifyMode(SslVerifyMode.CA).build(); - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster").sslOptions(sslOptions) - .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").sslOptions(sslOptions) + .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); fail("It should fail after all cluster attempts."); } catch (JedisClusterOperationException e) { @@ -202,18 +224,24 @@ public void connectWithCustomHostNameVerifier() { assertEquals("No more cluster attempts left.", e.getMessage()); } - try (JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 8379), - DefaultJedisClientConfig.builder().password("cluster").sslOptions(sslOptions) - .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc2 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").sslOptions(sslOptions) + .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { } catch (JedisClusterOperationException e) { assertEquals("Could not initialize cluster slots cache.", e.getMessage()); } - try (JedisCluster jc3 = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster").sslOptions(sslOptions) - .hostnameVerifier(localhostVerifier).hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc3 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").sslOptions(sslOptions) + .hostnameVerifier(localhostVerifier).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc3.get("foo"); } } diff --git a/src/test/java/redis/clients/jedis/SSLJedisClusterTest.java b/src/test/java/redis/clients/jedis/SSLRedisClusterClientTest.java similarity index 64% rename from src/test/java/redis/clients/jedis/SSLJedisClusterTest.java rename to src/test/java/redis/clients/jedis/SSLRedisClusterClientTest.java index 7890ef51d9..5a15dca639 100644 --- a/src/test/java/redis/clients/jedis/SSLJedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/SSLRedisClusterClientTest.java @@ -26,7 +26,7 @@ @SinceRedisVersion(value = "7.0.0", message = "Redis 6.2.x returns non-tls port in CLUSTER SLOTS command. Enable for 6.2.x after test is fixed.") @Tag("integration") -public class SSLJedisClusterTest extends JedisClusterTestBase { +public class SSLRedisClusterClientTest extends RedisClusterClientTestBase { private static final int DEFAULT_REDIRECTIONS = 5; private static final ConnectionPoolConfig DEFAULT_POOL_CONFIG = new ConnectionPoolConfig(); @@ -48,7 +48,7 @@ public class SSLJedisClusterTest extends JedisClusterTestBase { return new HostAndPort(hostAndPort.getHost(), hostAndPort.getPort()); }; - private static final String trustStoreName = SSLJedisClusterTest.class.getSimpleName(); + private static final String trustStoreName = SSLRedisClusterClientTest.class.getSimpleName(); @BeforeAll public static void prepare() { @@ -65,9 +65,13 @@ public static void teardownTrustStore() { @Test public void testSSLDiscoverNodesAutomatically() { - try (JedisCluster jc = new JedisCluster(Collections.singleton(new HostAndPort("localhost", 8379)), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .hostAndPortMapper(hostAndPortMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); /** @@ -88,9 +92,13 @@ public void testSSLDiscoverNodesAutomatically() { jc.get("foo"); } - try (JedisCluster jc2 = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .hostAndPortMapper(hostAndPortMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc2 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc2.getClusterNodes(); assertEquals(3, clusterNodes.size()); assertTrue(clusterNodes.containsKey("127.0.0.1:8379")); @@ -102,9 +110,12 @@ public void testSSLDiscoverNodesAutomatically() { @Test public void testSSLWithoutPortMap() { - try (JedisCluster jc = new JedisCluster(Collections.singleton(new HostAndPort("localhost", 8379)), - DefaultJedisClientConfig.builder().password("cluster").ssl(true).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); /** @@ -126,10 +137,13 @@ public void testSSLWithoutPortMap() { @Test public void connectByIpAddress() { - try (JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); } } @@ -139,10 +153,13 @@ public void connectToNodesFailsWithSSLParametersAndNoHostMapping() { final SSLParameters sslParameters = new SSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .sslParameters(sslParameters).hostAndPortMapper(portMap).build(), DEFAULT_REDIRECTIONS, - DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .sslParameters(sslParameters).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); fail("It should fail after all cluster attempts."); // } catch (JedisClusterMaxAttemptsException e) { @@ -159,10 +176,13 @@ public void connectToNodesSucceedsWithSSLParametersAndHostMapping() { final SSLParameters sslParameters = new SSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); } } @@ -172,10 +192,13 @@ public void connectByIpAddressFailsWithSSLParameters() { final SSLParameters sslParameters = new SSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); - try (JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .sslParameters(sslParameters).hostAndPortMapper(hostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { // jc.get("key"); // Assert.fail("There should be no reachable node in cluster."); //// } catch (JedisNoReachableClusterNodeException e) { @@ -190,10 +213,13 @@ public void connectWithCustomHostNameVerifier() { HostnameVerifier hostnameVerifier = new TlsUtil.BasicHostnameVerifier(); HostnameVerifier localhostVerifier = new TlsUtil.LocalhostVerifier(); - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc.get("foo"); fail("It should fail after all cluster attempts."); // } catch (JedisClusterMaxAttemptsException e) { @@ -203,10 +229,13 @@ public void connectWithCustomHostNameVerifier() { assertEquals("No more cluster attempts left.", e.getMessage()); } - try (JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc2 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("127.0.0.1", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { // jc2.get("foo"); // Assert.fail("There should be no reachable node in cluster."); //// } catch (JedisNoReachableClusterNodeException e) { @@ -217,31 +246,40 @@ public void connectWithCustomHostNameVerifier() { assertEquals("Could not initialize cluster slots cache.", e.getMessage()); } - try (JedisCluster jc3 = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .hostnameVerifier(localhostVerifier).hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc3 = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .hostnameVerifier(localhostVerifier).hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { jc3.get("foo"); } } @Test public void connectWithCustomSocketFactory() throws Exception { - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) .sslSocketFactory(sslSocketFactoryForEnv(Paths.get("cluster-unbound/work/tls"))) - .hostAndPortMapper(portMap).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + .hostAndPortMapper(portMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals(3, jc.getClusterNodes().size()); } } @Test public void connectWithEmptyTrustStore() throws Exception { - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379), - DefaultJedisClientConfig.builder().password("cluster").ssl(true) - .sslSocketFactory(createTrustNoOneSslSocketFactory()).build(), - DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 8379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(true) + .sslSocketFactory(createTrustNoOneSslSocketFactory()).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { } catch (JedisClusterOperationException e) { assertEquals("Could not initialize cluster slots cache.", e.getMessage()); } @@ -251,9 +289,13 @@ public void connectWithEmptyTrustStore() throws Exception { public void defaultHostAndPortUsedIfMapReturnsNull() { HostAndPortMapper nullHostAndPortMap = (HostAndPort hostAndPort) -> null; - try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 7379), - DefaultJedisClientConfig.builder().password("cluster").ssl(false) - .hostAndPortMapper(nullHostAndPortMap).build(), DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(new HostAndPort("localhost", 7379))) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").ssl(false) + .hostAndPortMapper(nullHostAndPortMap).build()) + .maxAttempts(DEFAULT_REDIRECTIONS) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { Map clusterNodes = jc.getClusterNodes(); assertEquals(3, clusterNodes.size()); diff --git a/src/test/java/redis/clients/jedis/SentineledConnectionProviderTest.java b/src/test/java/redis/clients/jedis/SentineledConnectionProviderTest.java index 68309b15b0..23bfbe0a0a 100644 --- a/src/test/java/redis/clients/jedis/SentineledConnectionProviderTest.java +++ b/src/test/java/redis/clients/jedis/SentineledConnectionProviderTest.java @@ -148,7 +148,7 @@ public void initializeWithNotMonitoredMasterNameShouldThrowException() { public void checkCloseableConnections() throws Exception { GenericObjectPoolConfig config = new GenericObjectPoolConfig<>(); - try (JedisSentineled jedis = JedisSentineled + try (RedisSentinelClient jedis = RedisSentinelClient .builder().masterName(MASTER_NAME).clientConfig(DefaultJedisClientConfig.builder() .timeoutMillis(1000).password("foobared").database(2).build()) .poolConfig(config).sentinels(sentinels).build()) { @@ -164,7 +164,7 @@ public void checkResourceIsCloseable() { config.setMaxTotal(1); config.setBlockWhenExhausted(false); - try (JedisSentineled jedis = JedisSentineled + try (RedisSentinelClient jedis = RedisSentinelClient .builder().masterName(MASTER_NAME).clientConfig(DefaultJedisClientConfig.builder() .timeoutMillis(1000).password("foobared").database(2).build()) .poolConfig(config).sentinels(sentinels).build()) { @@ -190,7 +190,7 @@ public void testResetInvalidPassword() { DefaultRedisCredentialsProvider credentialsProvider = new DefaultRedisCredentialsProvider(new DefaultRedisCredentials(null, "foobared")); - try (JedisSentineled jedis = JedisSentineled.builder().masterName(MASTER_NAME) + try (RedisSentinelClient jedis = RedisSentinelClient.builder().masterName(MASTER_NAME) .clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000) .credentialsProvider(credentialsProvider).database(2).clientName("my_shiny_client_name") .build()) @@ -221,7 +221,7 @@ public void testResetValidPassword() { DefaultRedisCredentialsProvider credentialsProvider = new DefaultRedisCredentialsProvider(new DefaultRedisCredentials(null, "wrong password")); - try (JedisSentineled jedis = JedisSentineled.builder().masterName(MASTER_NAME) + try (RedisSentinelClient jedis = RedisSentinelClient.builder().masterName(MASTER_NAME) .clientConfig(DefaultJedisClientConfig.builder().timeoutMillis(2000) .credentialsProvider(credentialsProvider).database(2).clientName("my_shiny_client_name") .build()) diff --git a/src/test/java/redis/clients/jedis/authentication/RedisEntraIDClusterIntegrationTests.java b/src/test/java/redis/clients/jedis/authentication/RedisEntraIDClusterIntegrationTests.java index cd90631f24..be713d96b8 100644 --- a/src/test/java/redis/clients/jedis/authentication/RedisEntraIDClusterIntegrationTests.java +++ b/src/test/java/redis/clients/jedis/authentication/RedisEntraIDClusterIntegrationTests.java @@ -35,7 +35,7 @@ import redis.clients.jedis.HostAndPort; import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; public class RedisEntraIDClusterIntegrationTests { private static final Logger log = LoggerFactory @@ -70,8 +70,12 @@ public void testClusterInitWithAuthXManager() { ConnectionPoolConfig DEFAULT_POOL_CONFIG = new ConnectionPoolConfig(); - try (JedisCluster jc = new JedisCluster(hnp, config, defaultDirections, - DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hnp)) + .clientConfig(config) + .maxAttempts(defaultDirections) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals("OK", jc.set("foo", "bar")); assertEquals("bar", jc.get("foo")); @@ -108,7 +112,10 @@ public void testClusterWithReAuth() throws InterruptedException, ExecutionExcept ExecutorService executorService = Executors.newFixedThreadPool(2); CountDownLatch latch = new CountDownLatch(1); - try (JedisCluster jc = new JedisCluster(Collections.singleton(hnp), config)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hnp)) + .clientConfig(config) + .build()) { Runnable task = () -> { while (latch.getCount() > 0) { assertEquals("OK", jc.set("foo", "bar")); diff --git a/src/test/java/redis/clients/jedis/authentication/RedisEntraIDIntegrationTests.java b/src/test/java/redis/clients/jedis/authentication/RedisEntraIDIntegrationTests.java index 1b622ca57e..d639571fbb 100644 --- a/src/test/java/redis/clients/jedis/authentication/RedisEntraIDIntegrationTests.java +++ b/src/test/java/redis/clients/jedis/authentication/RedisEntraIDIntegrationTests.java @@ -65,7 +65,7 @@ import redis.clients.jedis.EndpointConfig; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.HostAndPorts; -import redis.clients.jedis.JedisPooled; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.exceptions.JedisAccessControlException; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.scenario.FaultInjectionClient; @@ -119,7 +119,10 @@ public void testJedisConfig() { DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() .authXManager(new AuthXManager(tokenAuthConfig)).build(); - JedisPooled jedis = new JedisPooled(new HostAndPort("localhost", 6379), jedisConfig); + RedisClient jedis = RedisClient.builder() + .hostAndPort(new HostAndPort("localhost", 6379)) + .clientConfig(jedisConfig) + .build(); assertNotNull(jedis); assertEquals(1, counter.get()); @@ -137,7 +140,10 @@ public void withSecret_azureServicePrincipalIntegrationTest() { DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() .authXManager(new AuthXManager(tokenAuthConfig)).build(); - try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(jedisConfig) + .build()) { String key = UUID.randomUUID().toString(); jedis.set(key, "value"); assertEquals("value", jedis.get(key)); @@ -156,7 +162,10 @@ public void withCertificate_azureServicePrincipalIntegrationTest() { DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() .authXManager(new AuthXManager(tokenAuthConfig)).build(); - try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(jedisConfig) + .build()) { String key = UUID.randomUUID().toString(); jedis.set(key, "value"); assertEquals("value", jedis.get(key)); @@ -198,7 +207,10 @@ public void renewalDuringOperationsTest() throws InterruptedException, Execution ExecutorService runner = Executors.newSingleThreadExecutor(); runner.submit(() -> { - try (JedisPooled jedis = new JedisPooled(hnp, jedisClientConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(jedisClientConfig) + .build()) { List> futures = new ArrayList<>(); for (int i = 0; i < 5; i++) { Future future = jedisExecutors.submit(() -> { @@ -259,7 +271,10 @@ public void allConnectionsReauthTest() throws InterruptedException, ExecutionExc List> futures = new ArrayList<>(); ExecutorService executor = Executors.newFixedThreadPool(5); - try (JedisPooled jedis = new JedisPooled(hnp, jedisClientConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(jedisClientConfig) + .build()) { for (int i = 0; i < 5; i++) { Future future = executor.submit(() -> { for (; System.currentTimeMillis() - startTime < 2000;) { @@ -308,7 +323,10 @@ public void connectionAuthWithExpiredTokenTest() { DefaultJedisClientConfig jedisClientConfig = DefaultJedisClientConfig.builder() .authXManager(authXManager).build(); - try (JedisPooled jedis = new JedisPooled(hnp, jedisClientConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(jedisClientConfig) + .build()) { for (int i = 0; i < 50; i++) { String key = UUID.randomUUID().toString(); jedis.set(key, "value"); @@ -346,7 +364,10 @@ public void networkPartitionEvictionTest() { DefaultJedisClientConfig jedisClientConfig = DefaultJedisClientConfig.builder() .authXManager(authXManager).build(); - try (JedisPooled jedis = new JedisPooled(hnp, jedisClientConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(jedisClientConfig) + .build()) { for (int i = 0; i < 5; i++) { String key = UUID.randomUUID().toString(); jedis.set(key, "value"); @@ -413,7 +434,10 @@ public void withDefaultCredentials_azureCredentialsIntegrationTest() { DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() .authXManager(new AuthXManager(tokenAuthConfig)).build(); - try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(jedisConfig) + .build()) { String key = UUID.randomUUID().toString(); jedis.set(key, "value"); assertEquals("value", jedis.get(key)); diff --git a/src/test/java/redis/clients/jedis/authentication/RedisEntraIDManagedIdentityIntegrationTests.java b/src/test/java/redis/clients/jedis/authentication/RedisEntraIDManagedIdentityIntegrationTests.java index 63b6b6cd8e..5ac42a1f82 100644 --- a/src/test/java/redis/clients/jedis/authentication/RedisEntraIDManagedIdentityIntegrationTests.java +++ b/src/test/java/redis/clients/jedis/authentication/RedisEntraIDManagedIdentityIntegrationTests.java @@ -17,7 +17,7 @@ import redis.clients.jedis.EndpointConfig; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.HostAndPorts; -import redis.clients.jedis.JedisPooled; +import redis.clients.jedis.RedisClient; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -55,7 +55,10 @@ public void withUserAssignedId_azureManagedIdentityIntegrationTest() { DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() .authXManager(new AuthXManager(tokenAuthConfig)).build(); - try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(jedisConfig) + .build()) { String key = UUID.randomUUID().toString(); jedis.set(key, "value"); assertEquals("value", jedis.get(key)); @@ -73,7 +76,10 @@ public void withSystemAssignedId_azureManagedIdentityIntegrationTest() { DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() .authXManager(new AuthXManager(tokenAuthConfig)).build(); - try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(jedisConfig) + .build()) { String key = UUID.randomUUID().toString(); jedis.set(key, "value"); assertEquals("value", jedis.get(key)); diff --git a/src/test/java/redis/clients/jedis/authentication/TokenBasedAuthenticationClusterIntegrationTests.java b/src/test/java/redis/clients/jedis/authentication/TokenBasedAuthenticationClusterIntegrationTests.java index 8b72109ae5..e18c4d8391 100644 --- a/src/test/java/redis/clients/jedis/authentication/TokenBasedAuthenticationClusterIntegrationTests.java +++ b/src/test/java/redis/clients/jedis/authentication/TokenBasedAuthenticationClusterIntegrationTests.java @@ -38,7 +38,7 @@ import redis.clients.jedis.HostAndPort; import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; public class TokenBasedAuthenticationClusterIntegrationTests { private static final Logger log = LoggerFactory @@ -85,8 +85,12 @@ public Token requestToken() { ConnectionPoolConfig DEFAULT_POOL_CONFIG = new ConnectionPoolConfig(); - try (JedisCluster jc = new JedisCluster(hnp, config, defaultDirections, - DEFAULT_POOL_CONFIG)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hnp)) + .clientConfig(config) + .maxAttempts(defaultDirections) + .poolConfig(DEFAULT_POOL_CONFIG) + .build()) { assertEquals("OK", jc.set("foo", "bar")); assertEquals("bar", jc.get("foo")); @@ -131,7 +135,10 @@ public Token requestToken() { ExecutorService executorService = Executors.newFixedThreadPool(2); CountDownLatch latch = new CountDownLatch(1); - try (JedisCluster jc = new JedisCluster(Collections.singleton(hnp), config)) { + try (RedisClusterClient jc = RedisClusterClient.builder() + .nodes(Collections.singleton(hnp)) + .clientConfig(config) + .build()) { Runnable task = () -> { while (latch.getCount() > 0) { assertEquals("OK", jc.set("foo", "bar")); diff --git a/src/test/java/redis/clients/jedis/authentication/TokenBasedAuthenticationIntegrationTests.java b/src/test/java/redis/clients/jedis/authentication/TokenBasedAuthenticationIntegrationTests.java index 628defda63..06f050d4a0 100644 --- a/src/test/java/redis/clients/jedis/authentication/TokenBasedAuthenticationIntegrationTests.java +++ b/src/test/java/redis/clients/jedis/authentication/TokenBasedAuthenticationIntegrationTests.java @@ -39,8 +39,8 @@ import redis.clients.jedis.EndpointConfig; import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisPooled; import redis.clients.jedis.JedisPubSub; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.RedisProtocol; import redis.clients.jedis.Protocol.Command; import redis.clients.jedis.exceptions.JedisException; @@ -62,7 +62,7 @@ public static void before() { } @Test - public void testJedisPooledForInitialAuth() { + public void testClientForInitialAuth() { String user = "default"; String password = endpointConfig.getPassword(); @@ -80,13 +80,16 @@ public void testJedisPooledForInitialAuth() { JedisClientConfig clientConfig = DefaultJedisClientConfig.builder() .authXManager(new AuthXManager(tokenAuthConfig)).build(); - try (JedisPooled jedis = new JedisPooled(endpointConfig.getHostAndPort(), clientConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpointConfig.getHostAndPort()) + .clientConfig(clientConfig) + .build()) { jedis.get("key1"); } } @Test - public void testJedisPooledReauth() { + public void testClientReauth() { String user = "default"; String password = endpointConfig.getPassword(); @@ -115,7 +118,10 @@ public void testJedisPooledReauth() { JedisClientConfig clientConfig = DefaultJedisClientConfig.builder().authXManager(authXManager) .build(); - try (JedisPooled jedis = new JedisPooled(endpointConfig.getHostAndPort(), clientConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpointConfig.getHostAndPort()) + .clientConfig(clientConfig) + .build()) { AtomicBoolean stop = new AtomicBoolean(false); ExecutorService executor = Executors.newSingleThreadExecutor(); executor.submit(() -> { @@ -159,7 +165,10 @@ public void onSubscribe(String channel, int subscribedChannels) { } }; - try (JedisPooled jedis = new JedisPooled(endpointConfig.getHostAndPort(), clientConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpointConfig.getHostAndPort()) + .clientConfig(clientConfig) + .build()) { jedis.subscribe(pubSub, "channel1"); } } @@ -196,7 +205,10 @@ public void testJedisPubSubReauth() { JedisPubSub pubSub = new JedisPubSub() { }; - try (JedisPooled jedis = new JedisPooled(endpointConfig.getHostAndPort(), clientConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpointConfig.getHostAndPort()) + .clientConfig(clientConfig) + .build()) { ExecutorService executor = Executors.newSingleThreadExecutor(); executor.submit(() -> { jedis.subscribe(pubSub, "channel1"); @@ -241,7 +253,10 @@ public void testJedisPubSubWithResp2() { JedisClientConfig clientConfig = DefaultJedisClientConfig.builder() .authXManager(new AuthXManager(tokenAuthConfig)).build(); - try (JedisPooled jedis = new JedisPooled(endpointConfig.getHostAndPort(), clientConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpointConfig.getHostAndPort()) + .clientConfig(clientConfig) + .build()) { JedisPubSub pubSub = new JedisPubSub() {}; JedisException e = assertThrows(JedisException.class, () -> jedis.subscribe(pubSub, "channel1")); diff --git a/src/test/java/redis/clients/jedis/benchmark/PooledBenchmark.java b/src/test/java/redis/clients/jedis/benchmark/RedisClientBenchmark.java similarity index 83% rename from src/test/java/redis/clients/jedis/benchmark/PooledBenchmark.java rename to src/test/java/redis/clients/jedis/benchmark/RedisClientBenchmark.java index 9641d10d0c..8e8a81c9af 100644 --- a/src/test/java/redis/clients/jedis/benchmark/PooledBenchmark.java +++ b/src/test/java/redis/clients/jedis/benchmark/RedisClientBenchmark.java @@ -6,7 +6,7 @@ import redis.clients.jedis.*; -public class PooledBenchmark { +public class RedisClientBenchmark { private static EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0"); private static final int TOTAL_OPERATIONS = 100000; @@ -24,7 +24,12 @@ public static void main(String[] args) throws Exception { } private static void withPool() throws Exception { - final JedisPooled j = new JedisPooled(endpoint.getHost(), endpoint.getPort(), null, endpoint.getPassword()); + final RedisClient j = RedisClient.builder() + .hostAndPort(endpoint.getHost(), endpoint.getPort()) + .clientConfig(DefaultJedisClientConfig.builder() + .password(endpoint.getPassword()) + .build()) + .build(); List tds = new ArrayList<>(); final AtomicInteger ind = new AtomicInteger(); diff --git a/src/test/java/redis/clients/jedis/benchmark/CSCPooleadBenchmark.java b/src/test/java/redis/clients/jedis/benchmark/RedisClientCSCBenchmark.java similarity index 91% rename from src/test/java/redis/clients/jedis/benchmark/CSCPooleadBenchmark.java rename to src/test/java/redis/clients/jedis/benchmark/RedisClientCSCBenchmark.java index 8ee0580011..3f4d34294e 100644 --- a/src/test/java/redis/clients/jedis/benchmark/CSCPooleadBenchmark.java +++ b/src/test/java/redis/clients/jedis/benchmark/RedisClientCSCBenchmark.java @@ -8,7 +8,7 @@ import redis.clients.jedis.csc.Cache; import redis.clients.jedis.csc.TestCache; -public class CSCPooleadBenchmark { +public class RedisClientCSCBenchmark { private static EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0"); private static final int TOTAL_OPERATIONS = 1000000; @@ -50,7 +50,11 @@ private static void withPool(Cache cache) throws Exception { .password(endpoint.getPassword()).build(); List tds = new ArrayList<>(); final AtomicInteger ind = new AtomicInteger(); - try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), config, cache)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(config) + .cache(cache) + .build()) { for (int i = 0; i < NUMBER_OF_THREADS; i++) { Thread hj = new Thread(new Runnable() { @Override @@ -74,6 +78,6 @@ public void run() { for (Thread t : tds) { t.join(); } - } + } } } diff --git a/src/test/java/redis/clients/jedis/builders/ClientBuilderTest.java b/src/test/java/redis/clients/jedis/builders/ClientBuilderTest.java index eda2f223fb..c5ac78a449 100644 --- a/src/test/java/redis/clients/jedis/builders/ClientBuilderTest.java +++ b/src/test/java/redis/clients/jedis/builders/ClientBuilderTest.java @@ -18,9 +18,7 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import redis.clients.jedis.CommandObject; -import redis.clients.jedis.JedisPooled; -import redis.clients.jedis.JedisSentineled; +import redis.clients.jedis.*; import redis.clients.jedis.args.Rawable; import redis.clients.jedis.csc.Cache; import redis.clients.jedis.executors.CommandExecutor; @@ -49,7 +47,7 @@ private static List argsToStrings(CommandObject co) { @Test void appliesKeyPreprocessorToCommandObjects() { - try (JedisPooled client = JedisPooled.builder().commandExecutor(exec) + try (RedisClient client = RedisClient.builder().commandExecutor(exec) .connectionProvider(provider).keyPreProcessor(k -> "prefix:" + k).build()) { client.set("key", "v"); @@ -63,7 +61,7 @@ void appliesJsonObjectMapper() { JsonObjectMapper mapper = mock(JsonObjectMapper.class); when(mapper.toJson(any())).thenReturn("JSON:{a=1}"); - try (JedisPooled client = JedisPooled.builder().commandExecutor(exec) + try (RedisClient client = RedisClient.builder().commandExecutor(exec) .connectionProvider(provider).jsonObjectMapper(mapper).build()) { client.jsonSetWithEscape("k", Path2.ROOT_PATH, Collections.singletonMap("a", 1)); @@ -74,7 +72,7 @@ void appliesJsonObjectMapper() { @Test void appliesSearchDialect() { - try (JedisPooled client = JedisPooled.builder().commandExecutor(exec) + try (RedisClient client = RedisClient.builder().commandExecutor(exec) .connectionProvider(provider).searchDialect(3).build()) { client.ftSearch("idx", "q", new FTSearchParams()); @@ -88,7 +86,7 @@ void appliesSearchDialect() { void cacheRequiresRESP3() { Cache cache = mock(Cache.class); - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> JedisPooled + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> RedisClient .builder().commandExecutor(exec).connectionProvider(provider).cache(cache).build(), "Cache requires RESP3"); @@ -99,7 +97,7 @@ void cacheRequiresRESP3() { @Test void standaloneValidateHostPortRequired() { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> JedisPooled.builder().hostAndPort(null).build()); + () -> RedisClient.builder().hostAndPort(null).build()); assertThat(ex.getMessage(), containsString("Either URI or host/port must be specified")); } @@ -107,15 +105,15 @@ void standaloneValidateHostPortRequired() { @Test void sentinelValidateMasterAndSentinels() { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> JedisSentineled.builder().build()); + () -> RedisSentinelClient.builder().build()); assertThat(ex.getMessage(), containsString("Master name is required for Sentinel mode")); ex = assertThrows(IllegalArgumentException.class, - () -> JedisSentineled.builder().masterName("mymaster").build()); + () -> RedisSentinelClient.builder().masterName("mymaster").build()); assertThat(ex.getMessage(), containsString("At least one sentinel must be specified for Sentinel mode")); - ex = assertThrows(IllegalArgumentException.class, () -> JedisSentineled.builder() + ex = assertThrows(IllegalArgumentException.class, () -> RedisSentinelClient.builder() .masterName("mymaster").sentinels(Collections.emptySet()).build()); assertThat(ex.getMessage(), containsString("At least one sentinel must be specified for Sentinel mode")); diff --git a/src/test/java/redis/clients/jedis/builders/ClusterClientBuilderTest.java b/src/test/java/redis/clients/jedis/builders/ClusterClientBuilderTest.java index 365a896fb0..bd78be0b9c 100644 --- a/src/test/java/redis/clients/jedis/builders/ClusterClientBuilderTest.java +++ b/src/test/java/redis/clients/jedis/builders/ClusterClientBuilderTest.java @@ -27,7 +27,7 @@ import redis.clients.jedis.CommandObject; import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; import redis.clients.jedis.args.Rawable; import redis.clients.jedis.executors.CommandExecutor; import redis.clients.jedis.json.JsonObjectMapper; @@ -62,9 +62,7 @@ private static Set someNodes() { @Test void clusterNodesEmptyShouldThrow() { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> new JedisCluster.Builder() { - - }.nodes(new HashSet<>()).build()); + () -> RedisClusterClient.builder().nodes(new HashSet<>()).build()); assertThat(ex.getMessage(), containsString("At least one cluster node must be specified for cluster mode")); @@ -73,9 +71,8 @@ void clusterNodesEmptyShouldThrow() { @Test void negativeMaxTotalRetriesDurationShouldThrow() { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> new JedisCluster.Builder() { - - }.nodes(someNodes()).maxTotalRetriesDuration(Duration.ofMillis(-1)).build()); + () -> RedisClusterClient.builder().nodes(someNodes()) + .maxTotalRetriesDuration(Duration.ofMillis(-1)).build()); assertThat(ex.getMessage(), containsString("Max total retries duration cannot be negative for cluster mode")); @@ -84,9 +81,8 @@ void negativeMaxTotalRetriesDurationShouldThrow() { @Test void negativeTopologyRefreshShouldThrow() { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> new JedisCluster.Builder() { - - }.nodes(someNodes()).topologyRefreshPeriod(Duration.ofMillis(-1)).build()); + () -> RedisClusterClient.builder().nodes(someNodes()) + .topologyRefreshPeriod(Duration.ofMillis(-1)).build()); assertThat(ex.getMessage(), containsString("Topology refresh period cannot be negative for cluster mode")); @@ -94,7 +90,7 @@ void negativeTopologyRefreshShouldThrow() { @Test void buildWithPositiveDurationsAndConfig_usesProvidedExecAndProvider() { - try (JedisCluster client = JedisCluster.builder().nodes(someNodes()) + try (RedisClusterClient client = RedisClusterClient.builder().nodes(someNodes()) .clientConfig(redis.clients.jedis.DefaultJedisClientConfig.builder().build()).maxAttempts(3) .maxTotalRetriesDuration(Duration.ofMillis(10)).topologyRefreshPeriod(Duration.ofMillis(50)) .connectionProvider(provider).commandExecutor(exec).build()) { @@ -108,9 +104,7 @@ void buildWithPositiveDurationsAndConfig_usesProvidedExecAndProvider() { @Test void nodesNotProvidedShouldThrow() { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> new JedisCluster.Builder() { - - }.build()); + () -> RedisClusterClient.builder().build()); assertThat(ex.getMessage(), containsString("At least one cluster node must be specified for cluster mode")); @@ -119,16 +113,16 @@ void nodesNotProvidedShouldThrow() { @Test void searchDialectZeroShouldThrow() { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> JedisCluster.builder().searchDialect(0)); + () -> RedisClusterClient.builder().searchDialect(0)); assertThat(ex.getMessage(), containsString("DIALECT=0 cannot be set.")); } @Test void keyPreprocessorAppliedInCluster() { - try ( - JedisCluster client = JedisCluster.builder().nodes(someNodes()).connectionProvider(provider) - .commandExecutor(exec).keyPreProcessor(k -> "prefix:" + k).build()) { + try (RedisClusterClient client = RedisClusterClient.builder().nodes(someNodes()) + .connectionProvider(provider).commandExecutor(exec).keyPreProcessor(k -> "prefix:" + k) + .build()) { client.set("k", "v"); verify(exec).executeCommand(cap.capture()); @@ -145,7 +139,7 @@ void jsonObjectMapperAppliedInCluster() { JsonObjectMapper mapper = Mockito.mock(JsonObjectMapper.class); when(mapper.toJson(Mockito.any())).thenReturn("JSON:obj"); - try (JedisCluster client = JedisCluster.builder().nodes(someNodes()) + try (RedisClusterClient client = RedisClusterClient.builder().nodes(someNodes()) .connectionProvider(provider).commandExecutor(exec).jsonObjectMapper(mapper).build()) { client.jsonSetWithEscape("k", Path2.ROOT_PATH, Collections.singletonMap("a", 1)); @@ -161,7 +155,7 @@ void jsonObjectMapperAppliedInCluster() { @Test void searchDialectAppliedInCluster() { - try (JedisCluster client = JedisCluster.builder().nodes(someNodes()) + try (RedisClusterClient client = RedisClusterClient.builder().nodes(someNodes()) .connectionProvider(provider).commandExecutor(exec).searchDialect(3).build()) { client.ftSearch("idx", "q", new FTSearchParams()); diff --git a/src/test/java/redis/clients/jedis/builders/RedisClusterClientMigrationIntegrationTest.java b/src/test/java/redis/clients/jedis/builders/RedisClusterClientMigrationIntegrationTest.java new file mode 100644 index 0000000000..a0f59888bf --- /dev/null +++ b/src/test/java/redis/clients/jedis/builders/RedisClusterClientMigrationIntegrationTest.java @@ -0,0 +1,286 @@ +package redis.clients.jedis.builders; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import redis.clients.jedis.Connection; +import redis.clients.jedis.ConnectionPoolConfig; +import redis.clients.jedis.DefaultJedisClientConfig; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.HostAndPorts; +import redis.clients.jedis.JedisClientConfig; +import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; + +/** + * Integration test that verifies migration compatibility from the legacy JedisCluster constructor + * to the new RedisClusterClient.Builder pattern. + *

+ * This test demonstrates that the following legacy JedisCluster constructor: + * + *

+ * public JedisCluster(Set<HostAndPort> clusterNodes, JedisClientConfig clientConfig, 
+ *                     int maxAttempts, GenericObjectPoolConfig<Connection> poolConfig)
+ * 
+ * + * can be replaced with the RedisClusterClient.Builder pattern while maintaining the same + * functionality. + */ +@Tag("integration") +public class RedisClusterClientMigrationIntegrationTest { + + private static final Set CLUSTER_NODES = new HashSet<>( + HostAndPorts.getStableClusterServers()); + private static final String PASSWORD = "cluster"; + private static final int MAX_ATTEMPTS = 3; + + private JedisCluster legacyCluster; + private RedisClusterClient newCluster; + + @BeforeEach + public void setUp() { + // Clean up any existing data before each test + cleanClusterData(); + } + + @AfterEach + public void tearDown() { + // Close connections + if (legacyCluster != null) { + legacyCluster.close(); + legacyCluster = null; + } + if (newCluster != null) { + newCluster.close(); + newCluster = null; + } + + // Clean up data after tests + cleanClusterData(); + } + + /** + * Test that verifies both approaches can handle cluster operations correctly. Tests constructor: + * JedisCluster(Set<HostAndPort>, JedisClientConfig, int, + * GenericObjectPoolConfig<Connection>) + */ + @Test + public void testSpringDataRedisConstructor() { + // Prepare common configuration + JedisClientConfig clientConfig = DefaultJedisClientConfig.builder().password(PASSWORD) + .socketTimeoutMillis(2000).connectionTimeoutMillis(2000).build(); + + GenericObjectPoolConfig poolConfig = new ConnectionPoolConfig(); + + // Create both cluster clients + legacyCluster = new JedisCluster(CLUSTER_NODES, clientConfig, MAX_ATTEMPTS, poolConfig); + newCluster = RedisClusterClient.builder().nodes(CLUSTER_NODES).clientConfig(clientConfig) + .maxAttempts(MAX_ATTEMPTS).poolConfig(poolConfig).build(); + + verifyBothClients(legacyCluster, newCluster); + } + + /** + * Test migration from constructor with username, password, clientName, and SSL. Tests + * constructor: JedisCluster(Set<HostAndPort>, int, int, int, String, String, String, + * GenericObjectPoolConfig<Connection>, boolean) + */ + @Test + public void testConstructorWithUsernamePasswordClientNameAndSsl() { + int connectionTimeout = 2000; + int socketTimeout = 2000; + String username = "default"; + String clientName = "test-client"; + boolean ssl = false; // SSL requires special cluster setup + + GenericObjectPoolConfig poolConfig = new ConnectionPoolConfig(); + + // Legacy constructor with username + legacyCluster = new JedisCluster(CLUSTER_NODES, connectionTimeout, socketTimeout, MAX_ATTEMPTS, + username, PASSWORD, clientName, poolConfig, ssl); + + // New Builder pattern + JedisClientConfig clientConfig = DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(connectionTimeout).socketTimeoutMillis(socketTimeout) + .user(username).password(PASSWORD).clientName(clientName).ssl(ssl).build(); + + newCluster = RedisClusterClient.builder().nodes(CLUSTER_NODES).clientConfig(clientConfig) + .maxAttempts(MAX_ATTEMPTS).poolConfig(poolConfig).build(); + + verifyBothClients(legacyCluster, newCluster); + } + + /** + * Test migration from constructor with password, clientName, and SSL (no username). Tests + * constructor: JedisCluster(Set<HostAndPort>, int, int, int, String, String, + * GenericObjectPoolConfig<Connection>, boolean) + */ + @Test + public void testConstructorWithPasswordClientNameAndSsl() { + int connectionTimeout = 2000; + int socketTimeout = 2000; + String clientName = "test-client"; + boolean ssl = false; // SSL requires special cluster setup + + GenericObjectPoolConfig poolConfig = new ConnectionPoolConfig(); + + // Legacy constructor without username + legacyCluster = new JedisCluster(CLUSTER_NODES, connectionTimeout, socketTimeout, MAX_ATTEMPTS, + PASSWORD, clientName, poolConfig, ssl); + + // New Builder pattern + JedisClientConfig clientConfig = DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(connectionTimeout).socketTimeoutMillis(socketTimeout) + .password(PASSWORD).clientName(clientName).ssl(ssl).build(); + + newCluster = RedisClusterClient.builder().nodes(CLUSTER_NODES).clientConfig(clientConfig) + .maxAttempts(MAX_ATTEMPTS).poolConfig(poolConfig).build(); + + verifyBothClients(legacyCluster, newCluster); + } + + /** + * Test migration from simple constructor with just nodes and poolConfig. Tests constructor: + * JedisCluster(Set<HostAndPort>, GenericObjectPoolConfig<Connection>) + */ + @Test + public void testConstructorWithNodesAndPoolConfig() { + GenericObjectPoolConfig poolConfig = new ConnectionPoolConfig(); + poolConfig.setMaxTotal(8); + poolConfig.setMaxIdle(8); + JedisClientConfig clientConfig = DefaultJedisClientConfig.builder().password(PASSWORD).build(); + + // Legacy constructor + legacyCluster = new JedisCluster(CLUSTER_NODES, clientConfig, poolConfig); + + // New Builder pattern - need to add password via clientConfig + newCluster = RedisClusterClient.builder().nodes(CLUSTER_NODES).clientConfig(clientConfig) + .poolConfig(poolConfig).build(); + + verifyBothClients(legacyCluster, newCluster); + } + + /** + * Test migration from constructor with connection timeout, socket timeout, maxAttempts, password, + * and poolConfig. Tests constructor: JedisCluster(Set<HostAndPort>, int, int, int, String, + * GenericObjectPoolConfig<Connection>) + */ + @Test + public void testConstructorWithTimeoutsPasswordAndPoolConfig() { + int connectionTimeout = 2000; + int socketTimeout = 2000; + + GenericObjectPoolConfig poolConfig = new ConnectionPoolConfig(); + + // Legacy constructor + legacyCluster = new JedisCluster(CLUSTER_NODES, connectionTimeout, socketTimeout, MAX_ATTEMPTS, + PASSWORD, poolConfig); + + // New Builder pattern + JedisClientConfig clientConfig = DefaultJedisClientConfig.builder() + .connectionTimeoutMillis(connectionTimeout).socketTimeoutMillis(socketTimeout) + .password(PASSWORD).build(); + + newCluster = RedisClusterClient.builder().nodes(CLUSTER_NODES).clientConfig(clientConfig) + .maxAttempts(MAX_ATTEMPTS).poolConfig(poolConfig).build(); + + verifyBothClients(legacyCluster, newCluster); + } + + /** + * Test migration from constructor with timeout, maxAttempts, and poolConfig. Tests constructor: + * JedisCluster(Set<HostAndPort>, int, int, GenericObjectPoolConfig<Connection>) + */ + @Test + public void testConstructorWithTimeoutMaxAttemptsAndPoolConfig() { + int timeout = 2000; + + GenericObjectPoolConfig poolConfig = new ConnectionPoolConfig(); + JedisClientConfig clientConfig = DefaultJedisClientConfig.builder().timeoutMillis(timeout) + .password(PASSWORD).build(); + + // Legacy constructor - uses same timeout for connection and socket + legacyCluster = new JedisCluster(CLUSTER_NODES, timeout, timeout, MAX_ATTEMPTS, PASSWORD, + poolConfig); + + // New Builder pattern + newCluster = RedisClusterClient.builder().nodes(CLUSTER_NODES).clientConfig(clientConfig) + .maxAttempts(MAX_ATTEMPTS).poolConfig(poolConfig).build(); + + verifyBothClients(legacyCluster, newCluster); + } + + /** + * Test migration from single HostAndPort constructor with poolConfig. Tests constructor: + * JedisCluster(HostAndPort, GenericObjectPoolConfig<Connection>) + */ + @Test + public void testConstructorWithSingleNodeAndPoolConfig() { + int timeout = 2000; + HostAndPort singleNode = HostAndPorts.getStableClusterServers().get(0); + GenericObjectPoolConfig poolConfig = new ConnectionPoolConfig(); + JedisClientConfig clientConfig = DefaultJedisClientConfig.builder().password(PASSWORD).build(); + + // Legacy constructor with single node + legacyCluster = new JedisCluster(singleNode, timeout, timeout, MAX_ATTEMPTS, PASSWORD, + poolConfig); + + // New Builder pattern - need to add password and wrap single node in a Set + Set singleNodeSet = new HashSet<>(); + singleNodeSet.add(singleNode); + + newCluster = RedisClusterClient.builder().nodes(singleNodeSet).clientConfig(clientConfig) + .poolConfig(poolConfig).build(); + + verifyBothClients(legacyCluster, newCluster); + } + + protected void verifyBothClients(JedisCluster legacyCluster, RedisClusterClient newCluster) { + // Verify both discovered the cluster nodes + assertNotNull(legacyCluster.getClusterNodes(), "Legacy cluster should discover cluster nodes"); + assertNotNull(newCluster.getClusterNodes(), "New cluster should discover cluster nodes"); + + // Both should have discovered the same number of nodes + assertEquals(legacyCluster.getClusterNodes().size(), newCluster.getClusterNodes().size(), + "Both approaches should discover the same number of cluster nodes"); + + // Test basic string operations + String key1 = "test-string-key"; + legacyCluster.set(key1, "value1"); + assertEquals("value1", newCluster.get(key1)); + + // Test increment operations + String key2 = "test-counter-key"; + legacyCluster.set(key2, "0"); + newCluster.incr(key2); + assertEquals("1", legacyCluster.get(key2)); + + // Clean up + newCluster.del(key1); + newCluster.del(key2); + } + + /** + * Helper method to clean up cluster data before and after tests. + */ + private void cleanClusterData() { + // Connect to each stable cluster node and flush data + for (HostAndPort node : HostAndPorts.getStableClusterServers()) { + try (redis.clients.jedis.Jedis jedis = new redis.clients.jedis.Jedis(node)) { + jedis.auth(PASSWORD); + jedis.flushDB(); + } catch (Exception e) { + // Ignore errors during cleanup + } + } + } +} diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ClusterJedisCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/jedis/ClusterJedisCommandsTestBase.java index eeecf1c5ca..6ddc54f9ff 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ClusterJedisCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ClusterJedisCommandsTestBase.java @@ -14,7 +14,7 @@ import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; import redis.clients.jedis.HostAndPorts; -import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; import redis.clients.jedis.util.EnabledOnCommandCondition; import redis.clients.jedis.util.JedisClusterCRC16; import redis.clients.jedis.util.RedisVersionCondition; @@ -30,7 +30,7 @@ public abstract class ClusterJedisCommandsTestBase { private HostAndPort nodeInfo2 = HostAndPorts.getClusterServers().get(1); private HostAndPort nodeInfo3 = HostAndPorts.getClusterServers().get(2); private final Set jedisClusterNode = new HashSet<>(); - JedisCluster cluster; + RedisClusterClient cluster; @RegisterExtension public RedisVersionCondition versionCondition = new RedisVersionCondition(nodeInfo1, DefaultJedisClientConfig.builder().password("cluster").build()); @@ -80,7 +80,10 @@ public void setUp() throws InterruptedException { waitForClusterReady(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - cluster = new JedisCluster(jedisClusterNode, null, "cluster"); + cluster = RedisClusterClient.builder() + .nodes(jedisClusterNode) + .clientConfig(DefaultJedisClientConfig.builder().password("cluster").build()) + .build(); } @AfterAll diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledAllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientAllKindOfValuesCommandsTest.java similarity index 65% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledAllKindOfValuesCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientAllKindOfValuesCommandsTest.java index a05efc8030..da8189bf3f 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledAllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientAllKindOfValuesCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -13,25 +13,27 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledAllKindOfValuesCommandsTest extends AllKindOfValuesCommandsTestBase { +public class RedisClientAllKindOfValuesCommandsTest extends AllKindOfValuesCommandsTestBase { @RegisterExtension - public RedisVersionCondition versionCondition = new RedisVersionCondition(PooledCommandsTestHelper.nodeInfo); + public RedisVersionCondition versionCondition = new RedisVersionCondition( + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension - public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition(PooledCommandsTestHelper.nodeInfo); + public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( + RedisClientCommandsTestHelper.nodeInfo); - public PooledAllKindOfValuesCommandsTest(RedisProtocol protocol) { + public RedisClientAllKindOfValuesCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBinaryValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientBinaryValuesCommandsTest.java similarity index 62% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBinaryValuesCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientBinaryValuesCommandsTest.java index fc7a012663..e1e1287239 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBinaryValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientBinaryValuesCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedClass; @@ -10,20 +10,20 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledBinaryValuesCommandsTest extends BinaryValuesCommandsTestBase { +public class RedisClientBinaryValuesCommandsTest extends BinaryValuesCommandsTestBase { - public PooledBinaryValuesCommandsTest(RedisProtocol protocol) { + public RedisClientBinaryValuesCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBitCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientBitCommandsTest.java similarity index 67% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBitCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientBitCommandsTest.java index 11e80bfa5f..39d7c54b0d 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledBitCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientBitCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -13,25 +13,27 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledBitCommandsTest extends BitCommandsTestBase { +public class RedisClientBitCommandsTest extends BitCommandsTestBase { @RegisterExtension - public RedisVersionCondition versionCondition = new RedisVersionCondition(PooledCommandsTestHelper.nodeInfo); + public RedisVersionCondition versionCondition = new RedisVersionCondition( + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension - public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition(PooledCommandsTestHelper.nodeInfo); + public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( + RedisClientCommandsTestHelper.nodeInfo); - public PooledBitCommandsTest(RedisProtocol protocol) { + public RedisClientBitCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledCommandsTestHelper.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientCommandsTestHelper.java similarity index 64% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledCommandsTestHelper.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientCommandsTestHelper.java index 7136142e80..5e05e20f06 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledCommandsTestHelper.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientCommandsTestHelper.java @@ -1,13 +1,13 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import redis.clients.jedis.*; -public class PooledCommandsTestHelper { +public class RedisClientCommandsTestHelper { public static final EndpointConfig nodeInfo = HostAndPorts.getRedisEndpoint("standalone0"); - public static JedisPooled getPooled(RedisProtocol redisProtocol) { - return JedisPooled.builder().hostAndPort(nodeInfo.getHostAndPort()).clientConfig(nodeInfo.getClientConfigBuilder() + public static RedisClient getClient(RedisProtocol redisProtocol) { + return RedisClient.builder().hostAndPort(nodeInfo.getHostAndPort()).clientConfig(nodeInfo.getClientConfigBuilder() .protocol(redisProtocol).build()).build(); } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledExtendedVectorSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientExtendedVectorSetCommandsTest.java similarity index 67% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledExtendedVectorSetCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientExtendedVectorSetCommandsTest.java index 9a91f29c07..11441d0d53 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledExtendedVectorSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientExtendedVectorSetCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedClass; @@ -12,27 +12,27 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledExtendedVectorSetCommandsTest extends ExtendedVectorSetCommandsTestBase { +public class RedisClientExtendedVectorSetCommandsTest extends ExtendedVectorSetCommandsTestBase { @RegisterExtension public RedisVersionCondition versionCondition = new RedisVersionCondition( - PooledCommandsTestHelper.nodeInfo); + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( - PooledCommandsTestHelper.nodeInfo); + RedisClientCommandsTestHelper.nodeInfo); - public PooledExtendedVectorSetCommandsTest(RedisProtocol protocol) { + public RedisClientExtendedVectorSetCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @Override protected void clearData() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledGeoCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientGeoCommandsTest.java similarity index 63% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledGeoCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientGeoCommandsTest.java index 57b9b87ad0..1f3ac08389 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledGeoCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientGeoCommandsTest.java @@ -1,6 +1,5 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; @@ -11,20 +10,20 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledGeoCommandsTest extends GeoCommandsTestBase { +public class RedisClientGeoCommandsTest extends GeoCommandsTestBase { - public PooledGeoCommandsTest(RedisProtocol protocol) { + public RedisClientGeoCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHashesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientHashesCommandsTest.java similarity index 66% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHashesCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientHashesCommandsTest.java index 68423d83b2..da496b42ad 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHashesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientHashesCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -13,25 +13,27 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledHashesCommandsTest extends HashesCommandsTestBase { +public class RedisClientHashesCommandsTest extends HashesCommandsTestBase { @RegisterExtension - public RedisVersionCondition versionCondition = new RedisVersionCondition(PooledCommandsTestHelper.nodeInfo); + public RedisVersionCondition versionCondition = new RedisVersionCondition( + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension - public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition(PooledCommandsTestHelper.nodeInfo); + public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( + RedisClientCommandsTestHelper.nodeInfo); - public PooledHashesCommandsTest(RedisProtocol protocol) { + public RedisClientHashesCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHyperLogLogCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientHyperLogLogCommandsTest.java similarity index 63% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHyperLogLogCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientHyperLogLogCommandsTest.java index aaccaa3de7..6dbea06a99 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledHyperLogLogCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientHyperLogLogCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedClass; @@ -9,20 +9,20 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledHyperLogLogCommandsTest extends HyperLogLogCommandsTestBase { +public class RedisClientHyperLogLogCommandsTest extends HyperLogLogCommandsTestBase { - public PooledHyperLogLogCommandsTest(RedisProtocol protocol) { + public RedisClientHyperLogLogCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledListCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientListCommandsTest.java similarity index 66% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledListCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientListCommandsTest.java index db3c5829a3..5919f86d57 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientListCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -13,25 +13,27 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledListCommandsTest extends ListCommandsTestBase { +public class RedisClientListCommandsTest extends ListCommandsTestBase { @RegisterExtension - public RedisVersionCondition versionCondition = new RedisVersionCondition(PooledCommandsTestHelper.nodeInfo); + public RedisVersionCondition versionCondition = new RedisVersionCondition( + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension - public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition(PooledCommandsTestHelper.nodeInfo); + public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( + RedisClientCommandsTestHelper.nodeInfo); - public PooledListCommandsTest(RedisProtocol protocol) { + public RedisClientListCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientMiscellaneousTest.java similarity index 91% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientMiscellaneousTest.java index 3e0616f8b3..c7ebb17e89 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientMiscellaneousTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; @@ -31,25 +31,27 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") @Tag("integration") -public class PooledMiscellaneousTest extends UnifiedJedisCommandsTestBase { +public class RedisClientMiscellaneousTest extends UnifiedJedisCommandsTestBase { @RegisterExtension - public RedisVersionCondition versionCondition = new RedisVersionCondition(PooledCommandsTestHelper.nodeInfo); + public RedisVersionCondition versionCondition = new RedisVersionCondition( + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension - public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition(PooledCommandsTestHelper.nodeInfo); + public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( + RedisClientCommandsTestHelper.nodeInfo); - public PooledMiscellaneousTest(RedisProtocol protocol) { + public RedisClientMiscellaneousTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } @Test diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientSetCommandsTest.java similarity index 67% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSetCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientSetCommandsTest.java index da2e94e34c..49852a2c49 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientSetCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -13,25 +13,27 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledSetCommandsTest extends SetCommandsTestBase { +public class RedisClientSetCommandsTest extends SetCommandsTestBase { @RegisterExtension - public RedisVersionCondition versionCondition = new RedisVersionCondition(PooledCommandsTestHelper.nodeInfo); + public RedisVersionCondition versionCondition = new RedisVersionCondition( + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension - public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition(PooledCommandsTestHelper.nodeInfo); + public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( + RedisClientCommandsTestHelper.nodeInfo); - public PooledSetCommandsTest(RedisProtocol protocol) { + public RedisClientSetCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientSortedSetCommandsTest.java similarity index 66% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSortedSetCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientSortedSetCommandsTest.java index 0889fcd886..692c9c373c 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledSortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientSortedSetCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -13,24 +13,26 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledSortedSetCommandsTest extends SortedSetCommandsTestBase { +public class RedisClientSortedSetCommandsTest extends SortedSetCommandsTestBase { @RegisterExtension - public RedisVersionCondition versionCondition = new RedisVersionCondition(PooledCommandsTestHelper.nodeInfo); + public RedisVersionCondition versionCondition = new RedisVersionCondition( + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension - public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition(PooledCommandsTestHelper.nodeInfo); + public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( + RedisClientCommandsTestHelper.nodeInfo); - public PooledSortedSetCommandsTest(RedisProtocol protocol) { + public RedisClientSortedSetCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStreamsBinaryCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientStreamsBinaryCommandsTest.java similarity index 69% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStreamsBinaryCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientStreamsBinaryCommandsTest.java index 19cbd733a0..3a4bb1c446 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStreamsBinaryCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientStreamsBinaryCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedClass; @@ -11,23 +11,23 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledStreamsBinaryCommandsTest extends StreamsBinaryCommandsTestBase { +public class RedisClientStreamsBinaryCommandsTest extends StreamsBinaryCommandsTestBase { @RegisterExtension public RedisVersionCondition versionCondition = new RedisVersionCondition( - PooledCommandsTestHelper.nodeInfo); + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( - PooledCommandsTestHelper.nodeInfo); + RedisClientCommandsTestHelper.nodeInfo); - public PooledStreamsBinaryCommandsTest(RedisProtocol protocol) { + public RedisClientStreamsBinaryCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStreamsCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientStreamsCommandsTest.java similarity index 70% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStreamsCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientStreamsCommandsTest.java index 42879ff7fe..c51ab75fb1 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStreamsCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientStreamsCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedClass; @@ -11,22 +11,22 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledStreamsCommandsTest extends StreamsCommandsTestBase { +public class RedisClientStreamsCommandsTest extends StreamsCommandsTestBase { @RegisterExtension public RedisVersionCondition versionCondition = new RedisVersionCondition( - PooledCommandsTestHelper.nodeInfo); + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( - PooledCommandsTestHelper.nodeInfo); + RedisClientCommandsTestHelper.nodeInfo); - public PooledStreamsCommandsTest(RedisProtocol protocol) { + public RedisClientStreamsCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStringValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientStringValuesCommandsTest.java similarity index 65% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStringValuesCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientStringValuesCommandsTest.java index 49a6bccbac..30d59f247a 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledStringValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientStringValuesCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -13,24 +13,26 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledStringValuesCommandsTest extends StringValuesCommandsTestBase { +public class RedisClientStringValuesCommandsTest extends StringValuesCommandsTestBase { @RegisterExtension - public RedisVersionCondition versionCondition = new RedisVersionCondition(PooledCommandsTestHelper.nodeInfo); + public RedisVersionCondition versionCondition = new RedisVersionCondition( + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension - public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition(PooledCommandsTestHelper.nodeInfo); + public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( + RedisClientCommandsTestHelper.nodeInfo); - public PooledStringValuesCommandsTest(RedisProtocol protocol) { + public RedisClientStringValuesCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledVectorSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientVectorSetCommandsTest.java similarity index 69% rename from src/test/java/redis/clients/jedis/commands/unified/pooled/PooledVectorSetCommandsTest.java rename to src/test/java/redis/clients/jedis/commands/unified/client/RedisClientVectorSetCommandsTest.java index 43bb389423..561b097042 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledVectorSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/client/RedisClientVectorSetCommandsTest.java @@ -1,4 +1,4 @@ -package redis.clients.jedis.commands.unified.pooled; +package redis.clients.jedis.commands.unified.client; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -13,27 +13,27 @@ @ParameterizedClass @MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions") -public class PooledVectorSetCommandsTest extends VectorSetCommandsTestBase { +public class RedisClientVectorSetCommandsTest extends VectorSetCommandsTestBase { @RegisterExtension public RedisVersionCondition versionCondition = new RedisVersionCondition( - PooledCommandsTestHelper.nodeInfo); + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( - PooledCommandsTestHelper.nodeInfo); + RedisClientCommandsTestHelper.nodeInfo); - public PooledVectorSetCommandsTest(RedisProtocol protocol) { + public RedisClientVectorSetCommandsTest(RedisProtocol protocol) { super(protocol); } @Override protected UnifiedJedis createTestClient() { - return PooledCommandsTestHelper.getPooled(protocol); + return RedisClientCommandsTestHelper.getClient(protocol); } @BeforeEach public void setUp() { - PooledCommandsTestHelper.clearData(); + RedisClientCommandsTestHelper.clearData(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterCommandsTestHelper.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterCommandsTestHelper.java index 4d32c8bba4..535baa69fb 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterCommandsTestHelper.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterCommandsTestHelper.java @@ -5,15 +5,15 @@ import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; import redis.clients.jedis.RedisProtocol; public class ClusterCommandsTestHelper { - static JedisCluster getCleanCluster(RedisProtocol protocol) { + static RedisClusterClient getCleanCluster(RedisProtocol protocol) { clearClusterData(); - return JedisCluster.builder().nodes(Collections.singleton(HostAndPorts.getStableClusterServers().get(0))) + return RedisClusterClient.builder().nodes(Collections.singleton(HostAndPorts.getStableClusterServers().get(0))) .clientConfig(DefaultJedisClientConfig.builder().password("cluster").protocol(protocol).build()).build(); } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/BinaryStreamsPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/BinaryStreamsPipelineCommandsTest.java index c22559e7a2..ce456e01fe 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/BinaryStreamsPipelineCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/BinaryStreamsPipelineCommandsTest.java @@ -87,10 +87,10 @@ public static Map offsets(Object... streamOffsets) { @BeforeEach public void setUpTestStream() { - jedis.del(STREAM_KEY_1); - jedis.del(STREAM_KEY_2); + client.del(STREAM_KEY_1); + client.del(STREAM_KEY_2); try { - jedis.xgroupCreate(STREAM_KEY_1, GROUP_NAME, + client.xgroupCreate(STREAM_KEY_1, GROUP_NAME, StreamEntryID.XGROUP_LAST_ENTRY.toString().getBytes(), true); } catch (JedisDataException e) { if (!e.getMessage().contains("BUSYGROUP")) { @@ -98,7 +98,7 @@ public void setUpTestStream() { } } try { - jedis.xgroupCreate(STREAM_KEY_2, GROUP_NAME, + client.xgroupCreate(STREAM_KEY_2, GROUP_NAME, StreamEntryID.XGROUP_LAST_ENTRY.toString().getBytes(), true); } catch (JedisDataException e) { if (!e.getMessage().contains("BUSYGROUP")) { @@ -111,7 +111,7 @@ public void setUpTestStream() { public void xreadBinary() { stream1Entries.forEach( - entry -> jedis.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); + entry -> client.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); Response>>> response = pipe.xreadBinary( XReadParams.xReadParams(), offsets(STREAM_KEY_1, "0-0")); @@ -128,7 +128,7 @@ public void xreadBinary() { public void xreadBinaryAsMap() { stream1Entries.forEach( - entry -> jedis.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); + entry -> client.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); Response>> response = pipe.xreadBinaryAsMap( XReadParams.xReadParams(), offsets(STREAM_KEY_1, "0-0")); @@ -145,9 +145,9 @@ public void xreadBinaryAsMapWithMultipleStreams() { // Add entries to the streams stream1Entries.forEach( - entry -> jedis.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); + entry -> client.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); stream2Entries.forEach( - entry -> jedis.xadd(STREAM_KEY_2, new XAddParams().id(entry.getID()), entry.getFields())); + entry -> client.xadd(STREAM_KEY_2, new XAddParams().id(entry.getID()), entry.getFields())); Response>> response = pipe.xreadBinaryAsMap( XReadParams.xReadParams(), offsets(STREAM_KEY_1, "0-0", STREAM_KEY_2, "0-0")); @@ -165,7 +165,7 @@ public void xreadBinaryAsMapWithMultipleStreams() { public void xreadGroupBinary() { // Add entries to the streams stream1Entries.forEach( - entry -> jedis.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); + entry -> client.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); Response>>> response = pipe.xreadGroupBinary( GROUP_NAME, CONSUMER_NAME, XReadGroupParams.xReadGroupParams(), @@ -185,7 +185,7 @@ public void xreadGroupBinary() { @Test public void xreadGroupBinaryAsMap() { stream1Entries.forEach( - entry -> jedis.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); + entry -> client.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); Response>> response = pipe.xreadGroupBinaryAsMap( GROUP_NAME, CONSUMER_NAME, XReadGroupParams.xReadGroupParams(), @@ -203,9 +203,9 @@ public void xreadGroupBinaryAsMap() { public void xreadGroupBinaryAsMapMultipleStreams() { // Add entries to the streams stream1Entries.forEach( - entry -> jedis.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); + entry -> client.xadd(STREAM_KEY_1, new XAddParams().id(entry.getID()), entry.getFields())); stream2Entries.forEach( - entry -> jedis.xadd(STREAM_KEY_2, new XAddParams().id(entry.getID()), entry.getFields())); + entry -> client.xadd(STREAM_KEY_2, new XAddParams().id(entry.getID()), entry.getFields())); Response>> response = pipe.xreadGroupBinaryAsMap(GROUP_NAME, CONSUMER_NAME, XReadGroupParams.xReadGroupParams(), diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java index 1083e0a73f..12a3b59090 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java @@ -197,7 +197,7 @@ public void georadius() { Map coordinateMap = new HashMap<>(); coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); - jedis.geoadd("Sicily", coordinateMap); + client.geoadd("Sicily", coordinateMap); Response> members1 = pipe.georadius("Sicily", 15, 37, 200, GeoUnit.KM); @@ -284,7 +284,7 @@ public void georadiusStore() { Map coordinateMap = new HashMap<>(); coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); - jedis.geoadd("Sicily", coordinateMap); + client.geoadd("Sicily", coordinateMap); Response size = pipe.georadiusStore("Sicily", 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam(), @@ -304,7 +304,7 @@ public void georadiusReadonly() { Map coordinateMap = new HashMap<>(); coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556)); coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669)); - jedis.geoadd("Sicily", coordinateMap); + client.geoadd("Sicily", coordinateMap); Response> members1 = pipe.georadiusReadonly("Sicily", 15, 37, 200, GeoUnit.KM); @@ -365,7 +365,7 @@ public void georadiusBinary() { Map bcoordinateMap = new HashMap<>(); bcoordinateMap.put(bA, new GeoCoordinate(13.361389, 38.115556)); bcoordinateMap.put(bB, new GeoCoordinate(15.087269, 37.502669)); - jedis.geoadd(bfoo, bcoordinateMap); + client.geoadd(bfoo, bcoordinateMap); Response> members1 = pipe.georadius(bfoo, 15, 37, 200, GeoUnit.KM); @@ -426,7 +426,7 @@ public void georadiusStoreBinary() { Map bcoordinateMap = new HashMap<>(); bcoordinateMap.put(bA, new GeoCoordinate(13.361389, 38.115556)); bcoordinateMap.put(bB, new GeoCoordinate(15.087269, 37.502669)); - jedis.geoadd(bfoo, bcoordinateMap); + client.geoadd(bfoo, bcoordinateMap); Response size = pipe.georadiusStore(bfoo, 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam(), @@ -446,7 +446,7 @@ public void georadiusReadonlyBinary() { Map bcoordinateMap = new HashMap<>(); bcoordinateMap.put(bA, new GeoCoordinate(13.361389, 38.115556)); bcoordinateMap.put(bB, new GeoCoordinate(15.087269, 37.502669)); - jedis.geoadd(bfoo, bcoordinateMap); + client.geoadd(bfoo, bcoordinateMap); Response> members1 = pipe.georadiusReadonly(bfoo, 15, 37, 200, GeoUnit.KM); @@ -503,9 +503,9 @@ public void georadiusReadonlyBinary() { @Test public void georadiusByMember() { - jedis.geoadd("Sicily", 13.583333, 37.316667, "Agrigento"); - jedis.geoadd("Sicily", 13.361389, 38.115556, "Palermo"); - jedis.geoadd("Sicily", 15.087269, 37.502669, "Catania"); + client.geoadd("Sicily", 13.583333, 37.316667, "Agrigento"); + client.geoadd("Sicily", 13.361389, 38.115556, "Palermo"); + client.geoadd("Sicily", 15.087269, 37.502669, "Catania"); Response> members1 = pipe.georadiusByMember("Sicily", "Agrigento", 100, GeoUnit.KM); @@ -548,9 +548,9 @@ public void georadiusByMember() { @Test public void georadiusByMemberStore() { - jedis.geoadd("Sicily", 13.583333, 37.316667, "Agrigento"); - jedis.geoadd("Sicily", 13.361389, 38.115556, "Palermo"); - jedis.geoadd("Sicily", 15.087269, 37.502669, "Catania"); + client.geoadd("Sicily", 13.583333, 37.316667, "Agrigento"); + client.geoadd("Sicily", 13.361389, 38.115556, "Palermo"); + client.geoadd("Sicily", 15.087269, 37.502669, "Catania"); Response size = pipe.georadiusByMemberStore("Sicily", "Agrigento", 100, GeoUnit.KM, GeoRadiusParam.geoRadiusParam(), @@ -566,9 +566,9 @@ public void georadiusByMemberStore() { @Test public void georadiusByMemberReadonly() { - jedis.geoadd("Sicily", 13.583333, 37.316667, "Agrigento"); - jedis.geoadd("Sicily", 13.361389, 38.115556, "Palermo"); - jedis.geoadd("Sicily", 15.087269, 37.502669, "Catania"); + client.geoadd("Sicily", 13.583333, 37.316667, "Agrigento"); + client.geoadd("Sicily", 13.361389, 38.115556, "Palermo"); + client.geoadd("Sicily", 15.087269, 37.502669, "Catania"); Response> members1 = pipe.georadiusByMemberReadonly("Sicily", "Agrigento", 100, GeoUnit.KM); @@ -611,9 +611,9 @@ public void georadiusByMemberReadonly() { @Test public void georadiusByMemberBinary() { - jedis.geoadd(bfoo, 13.583333, 37.316667, bA); - jedis.geoadd(bfoo, 13.361389, 38.115556, bB); - jedis.geoadd(bfoo, 15.087269, 37.502669, bC); + client.geoadd(bfoo, 13.583333, 37.316667, bA); + client.geoadd(bfoo, 13.361389, 38.115556, bB); + client.geoadd(bfoo, 15.087269, 37.502669, bC); Response> members1 = pipe.georadiusByMember(bfoo, bA, 100, GeoUnit.KM); @@ -655,9 +655,9 @@ public void georadiusByMemberBinary() { @Test public void georadiusByMemberStoreBinary() { - jedis.geoadd(bfoo, 13.583333, 37.316667, bA); - jedis.geoadd(bfoo, 13.361389, 38.115556, bB); - jedis.geoadd(bfoo, 15.087269, 37.502669, bC); + client.geoadd(bfoo, 13.583333, 37.316667, bA); + client.geoadd(bfoo, 13.361389, 38.115556, bB); + client.geoadd(bfoo, 15.087269, 37.502669, bC); Response size = pipe.georadiusByMemberStore(bfoo, bA, 100, GeoUnit.KM, GeoRadiusParam.geoRadiusParam(), @@ -673,9 +673,9 @@ public void georadiusByMemberStoreBinary() { @Test public void georadiusByMemberReadonlyBinary() { - jedis.geoadd(bfoo, 13.583333, 37.316667, bA); - jedis.geoadd(bfoo, 13.361389, 38.115556, bB); - jedis.geoadd(bfoo, 15.087269, 37.502669, bC); + client.geoadd(bfoo, 13.583333, 37.316667, bA); + client.geoadd(bfoo, 13.361389, 38.115556, bB); + client.geoadd(bfoo, 15.087269, 37.502669, bC); Response> members1 = pipe.georadiusByMemberReadonly(bfoo, bA, 100, GeoUnit.KM); @@ -717,9 +717,9 @@ public void georadiusByMemberReadonlyBinary() { @Test public void geosearch() { - jedis.geoadd("barcelona", 2.1909389952632d, 41.433791470673d, "place1"); - jedis.geoadd("barcelona", 2.1873744593677d, 41.406342043777d, "place2"); - jedis.geoadd("barcelona", 2.583333d, 41.316667d, "place3"); + client.geoadd("barcelona", 2.1909389952632d, 41.433791470673d, "place1"); + client.geoadd("barcelona", 2.1873744593677d, 41.406342043777d, "place2"); + client.geoadd("barcelona", 2.583333d, 41.316667d, "place3"); // FROMLONLAT and BYRADIUS Response> members1 = pipe.geosearch("barcelona", @@ -822,9 +822,9 @@ public void geosearchSearchParamWithoutByRadiousAndByBox() { @Test public void geosearchstore() { - jedis.geoadd("barcelona", 2.1909389952632d, 41.433791470673d, "place1"); - jedis.geoadd("barcelona", 2.1873744593677d, 41.406342043777d, "place2"); - jedis.geoadd("barcelona", 2.583333d, 41.316667d, "place3"); + client.geoadd("barcelona", 2.1909389952632d, 41.433791470673d, "place1"); + client.geoadd("barcelona", 2.1873744593677d, 41.406342043777d, "place2"); + client.geoadd("barcelona", 2.583333d, 41.316667d, "place3"); // FROMLONLAT and BYRADIUS Response membersCount1 = pipe.geosearchStore("tel-aviv", "barcelona", @@ -858,8 +858,8 @@ public void geosearchstore() { @Test public void geosearchstoreWithdist() { - jedis.geoadd("barcelona", 2.1909389952632d, 41.433791470673d, "place1"); - jedis.geoadd("barcelona", 2.1873744593677d, 41.406342043777d, "place2"); + client.geoadd("barcelona", 2.1909389952632d, 41.433791470673d, "place1"); + client.geoadd("barcelona", 2.1873744593677d, 41.406342043777d, "place2"); Response members = pipe.geosearchStoreStoreDist("tel-aviv", "barcelona", new GeoSearchParam().byRadius(3000, GeoUnit.M).fromLonLat(2.191d, 41.433d)); @@ -878,13 +878,13 @@ private void prepareGeoData() { coordinateMap.put("b", new GeoCoordinate(2, 3)); coordinateMap.put("c", new GeoCoordinate(3.314, 2.3241)); - assertEquals(3, jedis.geoadd("foo", coordinateMap)); + assertEquals(3, client.geoadd("foo", coordinateMap)); Map bcoordinateMap = new HashMap<>(); bcoordinateMap.put(bA, new GeoCoordinate(3, 4)); bcoordinateMap.put(bB, new GeoCoordinate(2, 3)); bcoordinateMap.put(bC, new GeoCoordinate(3.314, 2.3241)); - assertEquals(3, jedis.geoadd(bfoo, bcoordinateMap)); + assertEquals(3, client.geoadd(bfoo, bcoordinateMap)); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/ListPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/ListPipelineCommandsTest.java index 6c879ddc2e..edc4d4aeb7 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/ListPipelineCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/ListPipelineCommandsTest.java @@ -543,7 +543,7 @@ public void blpopDoubleWithSleep() { } catch (InterruptedException e) { logger.error("", e); } - jedis.lpush("foo", "bar"); + client.lpush("foo", "bar"); }).start(); result = pipe.blpop(1.2, "foo"); @@ -655,7 +655,7 @@ public void brpopDoubleWithSleep() { } catch (InterruptedException e) { logger.error("", e); } - jedis.lpush("foo", "bar"); + client.lpush("foo", "bar"); }).start(); result = pipe.brpop(1.2, "foo"); @@ -759,7 +759,7 @@ public void brpoplpush() { } catch (InterruptedException e) { logger.error("", e); } - jedis.lpush("foo", "a"); + client.lpush("foo", "a"); }).start(); Response element = pipe.brpoplpush("foo", "bar", 0); @@ -780,7 +780,7 @@ public void brpoplpush() { } catch (InterruptedException e) { logger.error("", e); } - jedis.lpush(bfoo, bA); + client.lpush(bfoo, bA); }).start(); Response belement = pipe.brpoplpush(bfoo, bbar, 0); @@ -920,7 +920,7 @@ public void blmove() { } catch (InterruptedException e) { logger.error("", e); } - jedis.rpush("foo", "bar1", "bar2", "bar3"); + client.rpush("foo", "bar1", "bar2", "bar3"); }).start(); Response response = pipe.blmove("foo", "bar", ListDirection.RIGHT, ListDirection.LEFT, 0); @@ -940,7 +940,7 @@ public void blmove() { } catch (InterruptedException e) { logger.error("", e); } - jedis.rpush(bfoo, b1, b2, b3); + client.rpush(bfoo, b1, b2, b3); }).start(); Response bresponse = pipe.blmove(bfoo, bbar, ListDirection.RIGHT, ListDirection.LEFT, 0); diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java index 7dbd0a48ab..a12b9ec010 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/PipelineCommandsTestBase.java @@ -8,12 +8,12 @@ import redis.clients.jedis.util.RedisVersionCondition; import redis.clients.jedis.*; import redis.clients.jedis.commands.CommandsTestsParameters; -import redis.clients.jedis.commands.unified.pooled.PooledCommandsTestHelper; +import redis.clients.jedis.commands.unified.client.RedisClientCommandsTestHelper; @Tag("integration") public abstract class PipelineCommandsTestBase { - protected JedisPooled jedis; + protected RedisClient client; protected Pipeline pipe; /** * Input data for parameterized tests. In principle all subclasses of this class should be @@ -23,9 +23,11 @@ public abstract class PipelineCommandsTestBase { protected final RedisProtocol protocol; @RegisterExtension - public RedisVersionCondition versionCondition = new RedisVersionCondition(PooledCommandsTestHelper.nodeInfo); + public RedisVersionCondition versionCondition = new RedisVersionCondition( + RedisClientCommandsTestHelper.nodeInfo); @RegisterExtension - public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition(PooledCommandsTestHelper.nodeInfo); + public EnabledOnCommandCondition enabledOnCommandCondition = new EnabledOnCommandCondition( + RedisClientCommandsTestHelper.nodeInfo); /** * The RESP protocol is to be injected by the subclasses, usually via JUnit * parameterized tests, because most of the subclassed tests are meant to be @@ -41,14 +43,14 @@ public PipelineCommandsTestBase(RedisProtocol protocol) { @BeforeEach public void setUp() { - jedis = PooledCommandsTestHelper.getPooled(protocol); - PooledCommandsTestHelper.clearData(); - pipe = jedis.pipelined(); + client = RedisClientCommandsTestHelper.getClient(protocol); + RedisClientCommandsTestHelper.clearData(); + pipe = client.pipelined(); } @AfterEach public void tearDown() { pipe.close(); - jedis.close(); + client.close(); } } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java index 4a6fba0101..bc8aeec3e9 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pipeline/StreamsPipelineCommandsTest.java @@ -227,7 +227,7 @@ public void xaddWithParamsNoMkStream() { nullValue() )); - assertFalse(jedis.exists("xadd-stream3")); + assertFalse(client.exists("xadd-stream3")); } @Test @@ -389,8 +389,8 @@ public void xrange() { @Test public void xrangeExclusive() { - StreamEntryID id1 = jedis.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f1", "v1")); - StreamEntryID id2 = jedis.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f2", "v2")); + StreamEntryID id1 = client.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f1", "v1")); + StreamEntryID id2 = client.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f2", "v2")); Response> range1 = pipe.xrange("xrange-stream", id1.toString(), "+", 2); Response> range2 = pipe.xrange("xrange-stream", "(" + id1, "+", 2); @@ -419,10 +419,10 @@ public void xreadWithParams() { )); Map map1 = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd(stream1, (StreamEntryID) null, map1); + StreamEntryID id1 = client.xadd(stream1, (StreamEntryID) null, map1); Map map2 = singletonMap("f2", "v2"); - StreamEntryID id2 = jedis.xadd(stream2, (StreamEntryID) null, map2); + StreamEntryID id2 = client.xadd(stream2, (StreamEntryID) null, map2); // Read only a single Stream Response>>> streams1 = @@ -476,7 +476,7 @@ public void xreadBlockZero() throws InterruptedException { @Override public void run() { long startTime = System.currentTimeMillis(); - Pipeline blockPipe = jedis.pipelined(); + Pipeline blockPipe = client.pipelined(); Map streamQuery = singletonMap("block0-stream", new StreamEntryID()); Response>>> read = blockPipe.xread(XReadParams.xReadParams().block(0), streamQuery); @@ -489,7 +489,7 @@ public void run() { }, "xread-block-0-thread"); t.start(); Thread.sleep(1000); - StreamEntryID addedId = jedis.xadd("block0-stream", (StreamEntryID) null, singletonMap("foo", "bar")); + StreamEntryID addedId = client.xadd("block0-stream", (StreamEntryID) null, singletonMap("foo", "bar")); t.join(); assertThat(readRef.get().stream().map(Entry::getKey).collect(Collectors.toList()), @@ -611,8 +611,8 @@ public void xrevrange() { @Test public void xrevrangeExclusive() { - StreamEntryID id1 = jedis.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f1", "v1")); - StreamEntryID id2 = jedis.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f2", "v2")); + StreamEntryID id1 = client.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f1", "v1")); + StreamEntryID id2 = client.xadd("xrange-stream", (StreamEntryID) null, singletonMap("f2", "v2")); Response> range1 = pipe.xrevrange("xrange-stream", "+", id1.toString(), 2); Response> range2 = pipe.xrevrange("xrange-stream", "+", "(" + id1, 2); @@ -625,7 +625,7 @@ public void xrevrangeExclusive() { @Test public void xgroup() { - StreamEntryID id1 = jedis.xadd("xgroup-stream", (StreamEntryID) null, singletonMap("f1", "v1")); + StreamEntryID id1 = client.xadd("xgroup-stream", (StreamEntryID) null, singletonMap("f1", "v1")); pipe.xgroupCreate("xgroup-stream", "consumer-group-name", null, false); pipe.xgroupSetID("xgroup-stream", "consumer-group-name", id1); @@ -651,9 +651,9 @@ public void xgroup() { public void xreadGroupWithParams() { // Simple xreadGroup with NOACK Map map1 = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xreadGroup-stream1", (StreamEntryID) null, map1); + StreamEntryID id1 = client.xadd("xreadGroup-stream1", (StreamEntryID) null, map1); - jedis.xgroupCreate("xreadGroup-stream1", "xreadGroup-group", null, false); + client.xgroupCreate("xreadGroup-stream1", "xreadGroup-group", null, false); Map streamQuery1 = singletonMap("xreadGroup-stream1", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); @@ -673,12 +673,12 @@ public void xreadGroupWithParams() { .map(StreamEntry::getFields).collect(Collectors.toList()), contains(map1)); Map map2 = singletonMap("f2", "v2"); - StreamEntryID id2 = jedis.xadd("xreadGroup-stream1", (StreamEntryID) null, map2); + StreamEntryID id2 = client.xadd("xreadGroup-stream1", (StreamEntryID) null, map2); Map map3 = singletonMap("f3", "v3"); - StreamEntryID id3 = jedis.xadd("xreadGroup-stream2", (StreamEntryID) null, map3); + StreamEntryID id3 = client.xadd("xreadGroup-stream2", (StreamEntryID) null, map3); - jedis.xgroupCreate("xreadGroup-stream2", "xreadGroup-group", null, false); + client.xgroupCreate("xreadGroup-stream2", "xreadGroup-group", null, false); // Read only a single Stream Response>>> streams2 = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", @@ -714,7 +714,7 @@ public void xreadGroupWithParams() { // Read only fresh messages Map map4 = singletonMap("f4", "v4"); - StreamEntryID id4 = jedis.xadd("xreadGroup-stream1", (StreamEntryID) null, map4); + StreamEntryID id4 = client.xadd("xreadGroup-stream1", (StreamEntryID) null, map4); Map streamQueryFresh = singletonMap("xreadGroup-stream1", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); Response>>> streams4 = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", @@ -738,9 +738,9 @@ public void xreadGroupWithParamsWhenPendingMessageIsDiscarded() { Map map1 = singletonMap("f1", "v1"); XAddParams xAddParams = XAddParams.xAddParams().id(StreamEntryID.NEW_ENTRY).maxLen(2); - StreamEntryID firstMessageEntryId = jedis.xadd("xreadGroup-discard-stream1", xAddParams, map1); + StreamEntryID firstMessageEntryId = client.xadd("xreadGroup-discard-stream1", xAddParams, map1); - jedis.xadd("xreadGroup-discard-stream1", xAddParams, singletonMap("f2", "v2")); + client.xadd("xreadGroup-discard-stream1", xAddParams, singletonMap("f2", "v2")); pipe.xgroupCreate("xreadGroup-discard-stream1", "xreadGroup-group", null, false); @@ -762,7 +762,7 @@ public void xreadGroupWithParamsWhenPendingMessageIsDiscarded() { .map(StreamEntry::getFields).collect(Collectors.toList()), contains(map1)); // Add third message, the fields of pending message1 will be discarded by redis-server - jedis.xadd("xreadGroup-discard-stream1", xAddParams, singletonMap("f3", "v3")); + client.xadd("xreadGroup-discard-stream1", xAddParams, singletonMap("f3", "v3")); Map streamQueryPending = singletonMap("xreadGroup-discard-stream1", new StreamEntryID()); @@ -812,9 +812,9 @@ public void xack() { public void xpendingWithParams() { Map map = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, map); + StreamEntryID id1 = client.xadd("xpending-stream", (StreamEntryID) null, map); - assertEquals("OK", jedis.xgroupCreate("xpending-stream", "xpending-group", null, false)); + assertEquals("OK", client.xgroupCreate("xpending-stream", "xpending-group", null, false)); Map streamQeury1 = singletonMap("xpending-stream", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); @@ -862,8 +862,8 @@ public void xpendingWithParams() { @Test public void xpendingRange() { - StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, singletonMap("f1", "v1")); - StreamEntryID id2 = jedis.xadd("xpending-stream", (StreamEntryID) null, singletonMap("f2", "v2")); + StreamEntryID id1 = client.xadd("xpending-stream", (StreamEntryID) null, singletonMap("f1", "v1")); + StreamEntryID id2 = client.xadd("xpending-stream", (StreamEntryID) null, singletonMap("f2", "v2")); pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); @@ -896,7 +896,7 @@ public void xpendingRange() { @Test public void xclaimWithParams() throws InterruptedException { Map map1 = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, map1); + StreamEntryID id1 = client.xadd("xpending-stream", (StreamEntryID) null, map1); pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); @@ -938,7 +938,7 @@ public void xclaimWithParams() throws InterruptedException { @Test public void xclaimJustId() throws InterruptedException { Map map1 = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, map1); + StreamEntryID id1 = client.xadd("xpending-stream", (StreamEntryID) null, map1); pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); @@ -976,7 +976,7 @@ public void xclaimJustId() throws InterruptedException { @Test public void xautoclaim() throws InterruptedException { Map map1 = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xpending-stream", (StreamEntryID) null, map1); + StreamEntryID id1 = client.xadd("xpending-stream", (StreamEntryID) null, map1); pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); @@ -1016,7 +1016,7 @@ public void xautoclaim() throws InterruptedException { @Test public void xautoclaimBinary() throws InterruptedException { Map map1 = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xpending-stream", XAddParams.xAddParams(), map1); + StreamEntryID id1 = client.xadd("xpending-stream", XAddParams.xAddParams(), map1); pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); @@ -1060,7 +1060,7 @@ public void xautoclaimBinary() throws InterruptedException { @Test public void xautoclaimJustId() throws InterruptedException { Map map1 = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xpending-stream", XAddParams.xAddParams(), map1); + StreamEntryID id1 = client.xadd("xpending-stream", XAddParams.xAddParams(), map1); pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); @@ -1095,7 +1095,7 @@ public void xautoclaimJustId() throws InterruptedException { @Test public void xautoclaimJustIdBinary() throws InterruptedException { Map map1 = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("xpending-stream", XAddParams.xAddParams(), map1); + StreamEntryID id1 = client.xadd("xpending-stream", XAddParams.xAddParams(), map1); pipe.xgroupCreate("xpending-stream", "xpending-group", null, false); @@ -1145,9 +1145,9 @@ public void xinfo() throws InterruptedException { Map map1 = new HashMap<>(); map1.put(F1, V1); - StreamEntryID id1 = jedis.xadd(STREAM_NAME, (StreamEntryID) null, map1); + StreamEntryID id1 = client.xadd(STREAM_NAME, (StreamEntryID) null, map1); map1.put(F1, V2); - StreamEntryID id2 = jedis.xadd(STREAM_NAME, (StreamEntryID) null, map1); + StreamEntryID id2 = client.xadd(STREAM_NAME, (StreamEntryID) null, map1); Response streamInfoResponse = pipe.xinfoStream(STREAM_NAME); @@ -1215,7 +1215,7 @@ public void xinfo() throws InterruptedException { assertEquals(MY_CONSUMER, consumersInfo.get(0).getName()); assertEquals(0L, consumersInfo.get(0).getPending()); assertThat(consumersInfo.get(0).getIdle(), Matchers.greaterThanOrEqualTo(0L)); - if (RedisVersionUtil.getRedisVersion(jedis).isGreaterThanOrEqualTo(RedisVersion.V7_0_0)) { + if (RedisVersionUtil.getRedisVersion(client).isGreaterThanOrEqualTo(RedisVersion.V7_0_0)) { assertThat(consumersInfo.get(0).getInactive(), Matchers.any(Long.class)); } @@ -1231,7 +1231,7 @@ public void xinfo() throws InterruptedException { assertEquals(MY_CONSUMER, consumerInfo.get(0).getName()); assertEquals(0L, consumerInfo.get(0).getPending()); assertThat(consumerInfo.get(0).getIdle(), Matchers.greaterThanOrEqualTo(0L)); - if (RedisVersionUtil.getRedisVersion(jedis).isGreaterThanOrEqualTo(RedisVersion.V7_0_0)) { + if (RedisVersionUtil.getRedisVersion(client).isGreaterThanOrEqualTo(RedisVersion.V7_0_0)) { assertThat(consumerInfo.get(0).getInactive(), Matchers.any(Long.class)); } @@ -1288,9 +1288,9 @@ public void xinfo() throws InterruptedException { @Test public void xinfoStreamFullWithPending() { Map map = singletonMap("f1", "v1"); - StreamEntryID id1 = jedis.xadd("streamfull2", (StreamEntryID) null, map); - StreamEntryID id2 = jedis.xadd("streamfull2", (StreamEntryID) null, map); - jedis.xgroupCreate("streamfull2", "xreadGroup-group", null, false); + StreamEntryID id1 = client.xadd("streamfull2", (StreamEntryID) null, map); + StreamEntryID id2 = client.xadd("streamfull2", (StreamEntryID) null, map); + client.xgroupCreate("streamfull2", "xreadGroup-group", null, false); Map streamQeury1 = singletonMap("streamfull2", StreamEntryID.XREADGROUP_UNDELIVERED_ENTRY); Response>>> pending = pipe.xreadGroup("xreadGroup-group", "xreadGroup-consumer", @@ -1316,7 +1316,7 @@ public void xinfoStreamFullWithPending() { StreamConsumerFullInfo consumer = group.getConsumers().get(0); assertEquals("xreadGroup-consumer", consumer.getName()); assertThat(consumer.getSeenTime(), Matchers.greaterThanOrEqualTo(0L)); - if (RedisVersionUtil.getRedisVersion(jedis).isGreaterThanOrEqualTo(RedisVersion.V7_0_0)) { + if (RedisVersionUtil.getRedisVersion(client).isGreaterThanOrEqualTo(RedisVersion.V7_0_0)) { assertThat(consumer.getActiveTime(), Matchers.greaterThanOrEqualTo(0L)); } assertEquals(1, consumer.getPending().size()); diff --git a/src/test/java/redis/clients/jedis/commands/unified/sentinel/SentinelAllKindOfValuesCommandsIT.java b/src/test/java/redis/clients/jedis/commands/unified/sentinel/SentinelAllKindOfValuesCommandsIT.java index 7ffca8f3f8..d51e7c5061 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/sentinel/SentinelAllKindOfValuesCommandsIT.java +++ b/src/test/java/redis/clients/jedis/commands/unified/sentinel/SentinelAllKindOfValuesCommandsIT.java @@ -3,14 +3,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; -import redis.clients.jedis.DefaultJedisClientConfig; -import redis.clients.jedis.EndpointConfig; -import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.HostAndPorts; -import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisSentineled; -import redis.clients.jedis.RedisProtocol; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.*; import redis.clients.jedis.commands.unified.AllKindOfValuesCommandsTestBase; import redis.clients.jedis.util.EnabledOnCommandCondition; import redis.clients.jedis.util.RedisVersionCondition; @@ -48,7 +41,7 @@ public SentinelAllKindOfValuesCommandsIT(RedisProtocol protocol) { @Override protected UnifiedJedis createTestClient() { - return JedisSentineled.builder() + return RedisSentinelClient.builder() .clientConfig(primary.getClientConfigBuilder().protocol(protocol).build()) .sentinels(sentinels).sentinelClientConfig(sentinelClientConfig).masterName("mymaster") .build(); diff --git a/src/test/java/redis/clients/jedis/csc/AllowAndDenyListCacheableTest.java b/src/test/java/redis/clients/jedis/csc/AllowAndDenyListCacheableTest.java index 50b3ffb247..0408f00bac 100644 --- a/src/test/java/redis/clients/jedis/csc/AllowAndDenyListCacheableTest.java +++ b/src/test/java/redis/clients/jedis/csc/AllowAndDenyListCacheableTest.java @@ -4,8 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; -import redis.clients.jedis.JedisPooled; import redis.clients.jedis.Protocol; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.csc.util.AllowAndDenyListWithStringKeys; public class AllowAndDenyListCacheableTest extends ClientSideCacheTestBase { @@ -16,8 +16,12 @@ private static CacheConfig createConfig(Cacheable cacheable) { @Test public void none() { - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), - createConfig(new AllowAndDenyListWithStringKeys(null, null, null, null)), singleConnectionPoolConfig.get())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(createConfig(new AllowAndDenyListWithStringKeys(null, null, null, null))) + .poolConfig(singleConnectionPoolConfig.get()) + .build()) { Cache cache = jedis.getCache(); control.set("foo", "bar"); assertEquals(0, cache.getSize()); @@ -28,9 +32,12 @@ public void none() { @Test public void whiteListCommand() { - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), - createConfig(new AllowAndDenyListWithStringKeys(singleton(Protocol.Command.GET), null, null, null)), - singleConnectionPoolConfig.get())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(createConfig(new AllowAndDenyListWithStringKeys(singleton(Protocol.Command.GET), null, null, null))) + .poolConfig(singleConnectionPoolConfig.get()) + .build()) { Cache cache = jedis.getCache(); control.set("foo", "bar"); assertEquals(0, cache.getSize()); @@ -41,9 +48,12 @@ public void whiteListCommand() { @Test public void blackListCommand() { - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), - createConfig(new AllowAndDenyListWithStringKeys(null, singleton(Protocol.Command.GET), null, null)), - singleConnectionPoolConfig.get())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(createConfig(new AllowAndDenyListWithStringKeys(null, singleton(Protocol.Command.GET), null, null))) + .poolConfig(singleConnectionPoolConfig.get()) + .build()) { Cache cache = jedis.getCache(); control.set("foo", "bar"); assertEquals(0, cache.getSize()); @@ -54,8 +64,12 @@ public void blackListCommand() { @Test public void whiteListKey() { - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), - createConfig(new AllowAndDenyListWithStringKeys(null, null, singleton("foo"), null)), singleConnectionPoolConfig.get())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(createConfig(new AllowAndDenyListWithStringKeys(null, null, singleton("foo"), null))) + .poolConfig(singleConnectionPoolConfig.get()) + .build()) { control.set("foo", "bar"); Cache cache = jedis.getCache(); assertEquals(0, cache.getSize()); @@ -66,8 +80,12 @@ public void whiteListKey() { @Test public void blackListKey() { - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), - createConfig(new AllowAndDenyListWithStringKeys(null, null, null, singleton("foo"))), singleConnectionPoolConfig.get())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(createConfig(new AllowAndDenyListWithStringKeys(null, null, null, singleton("foo")))) + .poolConfig(singleConnectionPoolConfig.get()) + .build()) { Cache cache = jedis.getCache(); control.set("foo", "bar"); assertEquals(0, cache.getSize()); diff --git a/src/test/java/redis/clients/jedis/csc/ClientSideCacheFunctionalityTest.java b/src/test/java/redis/clients/jedis/csc/ClientSideCacheFunctionalityTest.java index 1836c0320f..3f10a61e18 100644 --- a/src/test/java/redis/clients/jedis/csc/ClientSideCacheFunctionalityTest.java +++ b/src/test/java/redis/clients/jedis/csc/ClientSideCacheFunctionalityTest.java @@ -25,7 +25,7 @@ import org.mockito.Mockito; import redis.clients.jedis.CommandObjects; -import redis.clients.jedis.JedisPooled; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.UnifiedJedis; public class ClientSideCacheFunctionalityTest extends ClientSideCacheTestBase { @@ -37,7 +37,11 @@ public void flushAllTest() { control.set("k" + i, "v" + i); } - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), CacheConfig.builder().build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().build()) + .build()) { Cache cache = jedis.getCache(); for (int i = 0; i < count; i++) { jedis.get("k" + i); @@ -61,7 +65,11 @@ public void lruEvictionTest() { Map map = new LinkedHashMap<>(count); Cache cache = new DefaultCache(count, map); - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), cache)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cache(cache) + .build()) { // Retrieve the 100 keys in the same order for (int i = 0; i < count; i++) { @@ -86,7 +94,11 @@ public void lruEvictionTest() { @Test // T.5.2 public void deleteByKeyUsingMGetTest() { - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), CacheConfig.builder().build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().build()) + .build()) { Cache clientSideCache = jedis.getCache(); jedis.set("1", "one"); @@ -110,7 +122,11 @@ public void deleteByKeyTest() { // By using LinkedHashMap, we can get the hashes (map keys) at the same order of the actual keys. LinkedHashMap map = new LinkedHashMap<>(); Cache clientSideCache = new TestCache(map); - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), clientSideCache)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cache(clientSideCache) + .build()) { for (int i = 0; i < count; i++) { jedis.get("k" + i); } @@ -141,7 +157,11 @@ public void deleteByKeysTest() { // By using LinkedHashMap, we can get the hashes (map keys) at the same order of the actual keys. LinkedHashMap map = new LinkedHashMap<>(); Cache clientSideCache = new TestCache(map); - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), clientSideCache)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cache(clientSideCache) + .build()) { for (int i = 0; i < count; i++) { jedis.get("k" + i); } @@ -164,7 +184,11 @@ public void deleteByEntryTest() { control.set("k" + i, "v" + i); } - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), CacheConfig.builder().build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().build()) + .build()) { Cache cache = jedis.getCache(); for (int i = 0; i < count; i++) { jedis.get("k" + i); @@ -189,7 +213,11 @@ public void deleteByEntriesTest() { control.set("k" + i, "v" + i); } - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), CacheConfig.builder().build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().build()) + .build()) { Cache cache = jedis.getCache(); for (int i = 0; i < count; i++) { jedis.get("k" + i); @@ -210,7 +238,11 @@ public void multiKeyOperation() { control.set("k1", "v1"); control.set("k2", "v2"); - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), CacheConfig.builder().build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().build()) + .build()) { jedis.mget("k1", "k2"); assertEquals(1, jedis.getCache().getSize()); } @@ -221,7 +253,11 @@ public void maximumSizeExact() { control.set("k1", "v1"); control.set("k2", "v2"); - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), CacheConfig.builder().maxSize(1).build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().maxSize(1).build()) + .build()) { Cache cache = jedis.getCache(); assertEquals(0, cache.getSize()); jedis.get("k1"); @@ -265,7 +301,11 @@ public void testInvalidationWithUnifiedJedis() { public void differentInstanceOnEachCacheHit() { // fill the cache for maxSize - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), CacheConfig.builder().build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().build()) + .build()) { Cache cache = jedis.getCache(); jedis.sadd("foo", "a"); jedis.sadd("foo", "b"); @@ -297,7 +337,11 @@ public void testSequentialAccess() throws InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(threadCount); CacheConfig cacheConfig = CacheConfig.builder().maxSize(1000).build(); - try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), clientConfig.get(), cacheConfig)) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(clientConfig.get()) + .cacheConfig(cacheConfig) + .build()) { // Submit multiple threads to perform concurrent operations CountDownLatch latch = new CountDownLatch(threadCount); for (int i = 0; i < threadCount; i++) { @@ -341,7 +385,11 @@ public void testConcurrentAccessWithStats() throws InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(threadCount); // Create the shared mock instance of cache - try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), clientConfig.get(), CacheConfig.builder().build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().build()) + .build()) { Cache cache = jedis.getCache(); // Submit multiple threads to perform concurrent operations CountDownLatch latch = new CountDownLatch(threadCount); @@ -378,7 +426,11 @@ public void testMaxSize() throws InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(threadCount); - try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), clientConfig.get(), CacheConfig.builder().maxSize(maxSize).build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().maxSize(maxSize).build()) + .build()) { Cache testCache = jedis.getCache(); // Submit multiple threads to perform concurrent operations CountDownLatch latch = new CountDownLatch(threadCount); @@ -417,8 +469,11 @@ public void testEvictionPolicy() throws InterruptedException { int touchOffset = 10; // fill the cache for maxSize - try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), clientConfig.get(), - CacheConfig.builder().maxSize(maxSize).build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().maxSize(maxSize).build()) + .build()) { Cache cache = jedis.getCache(); for (int i = 0; i < maxSize; i++) { jedis.set("foo" + i, "bar" + i); @@ -465,8 +520,11 @@ public void testEvictionPolicyMultithreaded() throws InterruptedException { List tds = new ArrayList<>(); final AtomicInteger ind = new AtomicInteger(); - try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), clientConfig.get(), - CacheConfig.builder().maxSize(MAX_SIZE).build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().maxSize(MAX_SIZE).build()) + .build()) { Cache cache = jedis.getCache(); for (int i = 0; i < NUMBER_OF_THREADS; i++) { Thread hj = new Thread(new Runnable() { @@ -505,7 +563,11 @@ public void testNullValue() throws InterruptedException { String nonExisting = "non-existing-key-"+ UUID.randomUUID().toString(); control.del(nonExisting); - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), CacheConfig.builder().maxSize(MAX_SIZE).build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().maxSize(MAX_SIZE).build()) + .build()) { Cache cache = jedis.getCache(); CacheStats stats = cache.getStats(); @@ -537,7 +599,11 @@ public void testNullValue() throws InterruptedException { @Test public void testCacheFactory() throws InterruptedException { // this checks the instantiation with parameters (int, EvictionPolicy, Cacheable) - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), CacheConfig.builder().cacheClass(TestCache.class).build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().cacheClass(TestCache.class).build()) + .build()) { Cache cache = jedis.getCache(); CacheStats stats = cache.getStats(); @@ -551,8 +617,11 @@ public void testCacheFactory() throws InterruptedException { } // this checks the instantiation with parameters (int, EvictionPolicy) - try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(), - CacheConfig.builder().cacheClass(TestCache.class).cacheable(null).build())) { + try (RedisClient jedis = RedisClient.builder() + .hostAndPort(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(CacheConfig.builder().cacheClass(TestCache.class).cacheable(null).build()) + .build()) { Cache cache = jedis.getCache(); CacheStats stats = cache.getStats(); diff --git a/src/test/java/redis/clients/jedis/csc/JedisSentineledClientSideCacheTest.java b/src/test/java/redis/clients/jedis/csc/JedisSentineledClientSideCacheTest.java deleted file mode 100644 index dd224f1f08..0000000000 --- a/src/test/java/redis/clients/jedis/csc/JedisSentineledClientSideCacheTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package redis.clients.jedis.csc; - -import io.redis.test.utils.RedisVersion; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; -import redis.clients.jedis.DefaultJedisClientConfig; -import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.HostAndPorts; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisSentineled; -import redis.clients.jedis.util.RedisVersionUtil; - -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -@Tag("integration") -public class JedisSentineledClientSideCacheTest extends UnifiedJedisClientSideCacheTestBase { - - private static final String MASTER_NAME = "mymaster"; - - protected static final HostAndPort sentinel1 = HostAndPorts.getSentinelServers().get(1); - protected static final HostAndPort sentinel2 = HostAndPorts.getSentinelServers().get(3); - - private static final Set sentinels = new HashSet<>(Arrays.asList(sentinel1, sentinel2)); - - private static final JedisClientConfig masterClientConfig = DefaultJedisClientConfig.builder().resp3().password("foobared").build(); - - private static final JedisClientConfig sentinelClientConfig = DefaultJedisClientConfig.builder().resp3().build(); - - @Override - protected JedisSentineled createRegularJedis() { - return new JedisSentineled(MASTER_NAME, masterClientConfig, sentinels, sentinelClientConfig); - } - - @Override - protected JedisSentineled createCachedJedis(CacheConfig cacheConfig) { - return new JedisSentineled(MASTER_NAME, masterClientConfig, cacheConfig, sentinels, sentinelClientConfig); - } - - @BeforeAll - public static void prepare() { - try (JedisSentineled sentinelClient = new JedisSentineled(MASTER_NAME, masterClientConfig, sentinels, sentinelClientConfig); - Jedis master = new Jedis(sentinelClient.getCurrentMaster(),masterClientConfig)) { - assumeTrue(RedisVersionUtil.getRedisVersion(master).isGreaterThanOrEqualTo(RedisVersion.V7_4), - "Jedis Client side caching is only supported with 'Redis 7.4' or later."); - } - } -} diff --git a/src/test/java/redis/clients/jedis/csc/JedisPooledClientSideCacheTest.java b/src/test/java/redis/clients/jedis/csc/RedisClientSideCacheTest.java similarity index 89% rename from src/test/java/redis/clients/jedis/csc/JedisPooledClientSideCacheTest.java rename to src/test/java/redis/clients/jedis/csc/RedisClientSideCacheTest.java index 9ff757fc4c..01e9dc006f 100644 --- a/src/test/java/redis/clients/jedis/csc/JedisPooledClientSideCacheTest.java +++ b/src/test/java/redis/clients/jedis/csc/RedisClientSideCacheTest.java @@ -9,7 +9,7 @@ @SinceRedisVersion(value = "7.4.0", message = "Jedis client-side caching is only supported with Redis 7.4 or later.") @Tag("integration") -public class JedisPooledClientSideCacheTest extends JedisPooledClientSideCacheTestBase { +public class RedisClientSideCacheTest extends RedisClientSideCacheTestBase { @RegisterExtension public static RedisVersionCondition versionCondition = new RedisVersionCondition( diff --git a/src/test/java/redis/clients/jedis/csc/JedisPooledClientSideCacheTestBase.java b/src/test/java/redis/clients/jedis/csc/RedisClientSideCacheTestBase.java similarity index 65% rename from src/test/java/redis/clients/jedis/csc/JedisPooledClientSideCacheTestBase.java rename to src/test/java/redis/clients/jedis/csc/RedisClientSideCacheTestBase.java index b5c630c274..a37774760e 100644 --- a/src/test/java/redis/clients/jedis/csc/JedisPooledClientSideCacheTestBase.java +++ b/src/test/java/redis/clients/jedis/csc/RedisClientSideCacheTestBase.java @@ -3,30 +3,37 @@ import org.junit.jupiter.api.Test; import redis.clients.jedis.EndpointConfig; import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPooled; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.args.ClientType; import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.params.ClientKillParams; import static org.junit.jupiter.api.Assertions.assertEquals; -public abstract class JedisPooledClientSideCacheTestBase extends UnifiedJedisClientSideCacheTestBase { +public abstract class RedisClientSideCacheTestBase extends UnifiedJedisClientSideCacheTestBase { protected static EndpointConfig endpoint; @Override - protected JedisPooled createRegularJedis() { - return new JedisPooled(endpoint.getHostAndPort(), endpoint.getClientConfigBuilder().build()); + protected RedisClient createRegularJedis() { + return RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(endpoint.getClientConfigBuilder().build()) + .build(); } @Override - protected JedisPooled createCachedJedis(CacheConfig cacheConfig) { - return new JedisPooled(endpoint.getHostAndPort(), endpoint.getClientConfigBuilder().resp3().build(), cacheConfig); + protected RedisClient createCachedJedis(CacheConfig cacheConfig) { + return RedisClient.builder() + .hostAndPort(endpoint.getHostAndPort()) + .clientConfig(endpoint.getClientConfigBuilder().resp3().build()) + .cacheConfig(cacheConfig) + .build(); } @Test public void clearIfOneDiesTest() { - try (JedisPooled jedis = createCachedJedis(CacheConfig.builder().build())) { + try (RedisClient jedis = createCachedJedis(CacheConfig.builder().build())) { Cache cache = jedis.getCache(); // Create 100 keys for (int i = 0; i < 100; i++) { diff --git a/src/test/java/redis/clients/jedis/csc/JedisClusterClientSideCacheTest.java b/src/test/java/redis/clients/jedis/csc/RedisClusterClientSideCacheTest.java similarity index 74% rename from src/test/java/redis/clients/jedis/csc/JedisClusterClientSideCacheTest.java rename to src/test/java/redis/clients/jedis/csc/RedisClusterClientSideCacheTest.java index 845e7c10f1..b49a68b4e1 100644 --- a/src/test/java/redis/clients/jedis/csc/JedisClusterClientSideCacheTest.java +++ b/src/test/java/redis/clients/jedis/csc/RedisClusterClientSideCacheTest.java @@ -14,12 +14,12 @@ import redis.clients.jedis.HostAndPort; import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; import redis.clients.jedis.util.RedisVersionCondition; @SinceRedisVersion(value = "7.4.0", message = "Jedis client-side caching is only supported with Redis 7.4 or later.") @Tag("integration") -public class JedisClusterClientSideCacheTest extends UnifiedJedisClientSideCacheTestBase { +public class RedisClusterClientSideCacheTest extends UnifiedJedisClientSideCacheTestBase { private static final Set hnp = new HashSet<>(HostAndPorts.getStableClusterServers()); @@ -37,13 +37,20 @@ public class JedisClusterClientSideCacheTest extends UnifiedJedisClientSideCache public static RedisVersionCondition versionCondition = new RedisVersionCondition(hnp.iterator().next(), clientConfig.get()); @Override - protected JedisCluster createRegularJedis() { - return new JedisCluster(hnp, clientConfig.get()); + protected RedisClusterClient createRegularJedis() { + return RedisClusterClient.builder() + .nodes(hnp) + .clientConfig(clientConfig.get()) + .build(); } @Override - protected JedisCluster createCachedJedis(CacheConfig cacheConfig) { - return new JedisCluster(hnp, clientConfig.get(), cacheConfig); + protected RedisClusterClient createCachedJedis(CacheConfig cacheConfig) { + return RedisClusterClient.builder() + .nodes(hnp) + .clientConfig(clientConfig.get()) + .cacheConfig(cacheConfig) + .build(); } } diff --git a/src/test/java/redis/clients/jedis/csc/RedisSentinelClientSideCacheTest.java b/src/test/java/redis/clients/jedis/csc/RedisSentinelClientSideCacheTest.java new file mode 100644 index 0000000000..deb0bc99fd --- /dev/null +++ b/src/test/java/redis/clients/jedis/csc/RedisSentinelClientSideCacheTest.java @@ -0,0 +1,56 @@ +package redis.clients.jedis.csc; + +import io.redis.test.utils.RedisVersion; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import redis.clients.jedis.*; +import redis.clients.jedis.util.RedisVersionUtil; + +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +@Tag("integration") +public class RedisSentinelClientSideCacheTest extends UnifiedJedisClientSideCacheTestBase { + + private static final String MASTER_NAME = "mymaster"; + + protected static final HostAndPort sentinel1 = HostAndPorts.getSentinelServers().get(1); + protected static final HostAndPort sentinel2 = HostAndPorts.getSentinelServers().get(3); + + private static final Set sentinels = new HashSet<>( + Arrays.asList(sentinel1, sentinel2)); + + private static final JedisClientConfig masterClientConfig = DefaultJedisClientConfig.builder() + .resp3().password("foobared").build(); + + private static final JedisClientConfig sentinelClientConfig = DefaultJedisClientConfig.builder() + .resp3().build(); + + @Override + protected RedisSentinelClient createRegularJedis() { + return RedisSentinelClient.builder().masterName(MASTER_NAME).clientConfig(masterClientConfig) + .sentinels(sentinels).sentinelClientConfig(sentinelClientConfig).build(); + } + + @Override + protected RedisSentinelClient createCachedJedis(CacheConfig cacheConfig) { + return RedisSentinelClient.builder().masterName(MASTER_NAME).clientConfig(masterClientConfig) + .sentinels(sentinels).sentinelClientConfig(sentinelClientConfig).cacheConfig(cacheConfig) + .build(); + } + + @BeforeAll + public static void prepare() { + try ( + RedisSentinelClient sentinelClient = RedisSentinelClient.builder().masterName(MASTER_NAME) + .clientConfig(masterClientConfig).sentinels(sentinels) + .sentinelClientConfig(sentinelClientConfig).build(); + Jedis master = new Jedis(sentinelClient.getCurrentMaster(), masterClientConfig)) { + assumeTrue(RedisVersionUtil.getRedisVersion(master).isGreaterThanOrEqualTo(RedisVersion.V7_4), + "Jedis Client side caching is only supported with 'Redis 7.4' or later."); + } + } +} diff --git a/src/test/java/redis/clients/jedis/csc/SSLJedisPooledClientSideCacheTest.java b/src/test/java/redis/clients/jedis/csc/SSLRedisClientSideCacheTest.java similarity index 87% rename from src/test/java/redis/clients/jedis/csc/SSLJedisPooledClientSideCacheTest.java rename to src/test/java/redis/clients/jedis/csc/SSLRedisClientSideCacheTest.java index dd7ca95448..8a4589704a 100644 --- a/src/test/java/redis/clients/jedis/csc/SSLJedisPooledClientSideCacheTest.java +++ b/src/test/java/redis/clients/jedis/csc/SSLRedisClientSideCacheTest.java @@ -16,9 +16,9 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; @Tag("integration") -public class SSLJedisPooledClientSideCacheTest extends JedisPooledClientSideCacheTestBase { +public class SSLRedisClientSideCacheTest extends RedisClientSideCacheTestBase { - private static final String trustStoreName = SSLJedisPooledClientSideCacheTest.class.getSimpleName(); + private static final String trustStoreName = SSLRedisClientSideCacheTest.class.getSimpleName(); @BeforeAll public static void prepare() { diff --git a/src/test/java/redis/clients/jedis/examples/BroadcastCommandsToAllClusterNodes.java b/src/test/java/redis/clients/jedis/examples/BroadcastCommandsToAllClusterNodes.java index dd85f28c09..6a321cceb6 100644 --- a/src/test/java/redis/clients/jedis/examples/BroadcastCommandsToAllClusterNodes.java +++ b/src/test/java/redis/clients/jedis/examples/BroadcastCommandsToAllClusterNodes.java @@ -1,7 +1,7 @@ package redis.clients.jedis.examples; import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; /** * When using the Open Source Redis Cluster @@ -16,7 +16,7 @@ public class BroadcastCommandsToAllClusterNodes { public static void main(String[] args) { HostAndPort clusterNode = new HostAndPort("127.0.0.1", 7000); - JedisCluster client = new JedisCluster(clusterNode); + RedisClusterClient client = new RedisClusterClient(clusterNode); String reply = client.configSet("maxmemory", "100mb"); // reply is "OK" } diff --git a/src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java b/src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java index b5c0153a2c..9119c5c00d 100644 --- a/src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java +++ b/src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java @@ -8,8 +8,7 @@ import org.locationtech.jts.io.WKTReader; import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.JedisPooled; -import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.RedisClient; import redis.clients.jedis.search.FTSearchParams; import redis.clients.jedis.search.SearchResult; import redis.clients.jedis.search.schemafields.GeoShapeField; @@ -51,7 +50,7 @@ public static void main(String[] args) { final int port = 6379; final HostAndPort address = new HostAndPort(host, port); - UnifiedJedis client = new JedisPooled(address); + RedisClient client = new RedisClient(address); // client.setDefaultSearchDialect(3); // we can set default search dialect for the client (UnifiedJedis) object // to avoid setting dialect in every query. diff --git a/src/test/java/redis/clients/jedis/examples/RedisCredentialsProviderUsage.java b/src/test/java/redis/clients/jedis/examples/RedisCredentialsProviderUsage.java index b0de49403a..28a88a9611 100644 --- a/src/test/java/redis/clients/jedis/examples/RedisCredentialsProviderUsage.java +++ b/src/test/java/redis/clients/jedis/examples/RedisCredentialsProviderUsage.java @@ -4,7 +4,7 @@ import redis.clients.jedis.DefaultRedisCredentials; import redis.clients.jedis.DefaultRedisCredentialsProvider; import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.JedisPooled; +import redis.clients.jedis.RedisClient; public class RedisCredentialsProviderUsage { @@ -23,7 +23,10 @@ public static void main(String[] args) { = DefaultJedisClientConfig.builder() .credentialsProvider(credentialsProvider).build(); - JedisPooled jedis = new JedisPooled(address, clientConfig); + RedisClient jedis = RedisClient.builder() + .hostAndPort(address) + .clientConfig(clientConfig) + .build(); // ... // do operations with jedis diff --git a/src/test/java/redis/clients/jedis/misc/ClusterInitErrorTest.java b/src/test/java/redis/clients/jedis/misc/ClusterInitErrorTest.java index b7ee96e542..c3d21649c3 100644 --- a/src/test/java/redis/clients/jedis/misc/ClusterInitErrorTest.java +++ b/src/test/java/redis/clients/jedis/misc/ClusterInitErrorTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test; import redis.clients.jedis.EndpointConfig; import redis.clients.jedis.HostAndPorts; -import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; import redis.clients.jedis.exceptions.JedisClusterOperationException; import static org.junit.jupiter.api.Assertions.assertNull; @@ -26,9 +26,10 @@ public void initError() { assertNull(System.getProperty(INIT_NO_ERROR_PROPERTY)); EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0"); assertThrows(JedisClusterOperationException.class, () -> { - try (JedisCluster cluster = new JedisCluster( - Collections.singleton(endpoint.getHostAndPort()), - endpoint.getClientConfigBuilder().build())) { + try (RedisClusterClient cluster = RedisClusterClient.builder() + .nodes(Collections.singleton(endpoint.getHostAndPort())) + .clientConfig(endpoint.getClientConfigBuilder().build()) + .build()) { // Intentionally left empty because the exception is expected } }); @@ -38,9 +39,10 @@ public void initError() { public void initNoError() { System.setProperty(INIT_NO_ERROR_PROPERTY, ""); EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0"); - try (JedisCluster cluster = new JedisCluster( - Collections.singleton(endpoint.getHostAndPort()), - endpoint.getClientConfigBuilder().build())) { + try (RedisClusterClient cluster = RedisClusterClient.builder() + .nodes(Collections.singleton(endpoint.getHostAndPort())) + .clientConfig(endpoint.getClientConfigBuilder().build()) + .build()) { assertThrows(JedisClusterOperationException.class, () -> cluster.get("foo")); } } diff --git a/src/test/java/redis/clients/jedis/prefix/JedisPooledPrefixedKeysTest.java b/src/test/java/redis/clients/jedis/prefix/JedisPooledPrefixedKeysTest.java index b7f841e82f..a794e56e28 100644 --- a/src/test/java/redis/clients/jedis/prefix/JedisPooledPrefixedKeysTest.java +++ b/src/test/java/redis/clients/jedis/prefix/JedisPooledPrefixedKeysTest.java @@ -2,16 +2,19 @@ import redis.clients.jedis.EndpointConfig; import redis.clients.jedis.HostAndPorts; -import redis.clients.jedis.JedisPooled; +import redis.clients.jedis.RedisClient; import org.junit.jupiter.api.Tag; @Tag("integration") -public class JedisPooledPrefixedKeysTest extends PrefixedKeysTest { +public class JedisPooledPrefixedKeysTest extends PrefixedKeysTest { private static final EndpointConfig ENDPOINT = HostAndPorts.getRedisEndpoint("standalone1"); @Override - JedisPooled nonPrefixingJedis() { - return new JedisPooled(ENDPOINT.getHostAndPort(), ENDPOINT.getClientConfigBuilder().timeoutMillis(500).build()); + RedisClient nonPrefixingJedis() { + return RedisClient.builder() + .hostAndPort(ENDPOINT.getHostAndPort()) + .clientConfig(ENDPOINT.getClientConfigBuilder().timeoutMillis(500).build()) + .build(); } } diff --git a/src/test/java/redis/clients/jedis/prefix/JedisClusterPrefixedKeysTest.java b/src/test/java/redis/clients/jedis/prefix/RedisClusterPrefixedKeysTest.java similarity index 74% rename from src/test/java/redis/clients/jedis/prefix/JedisClusterPrefixedKeysTest.java rename to src/test/java/redis/clients/jedis/prefix/RedisClusterPrefixedKeysTest.java index 03053a99ec..dd01bb37fe 100644 --- a/src/test/java/redis/clients/jedis/prefix/JedisClusterPrefixedKeysTest.java +++ b/src/test/java/redis/clients/jedis/prefix/RedisClusterPrefixedKeysTest.java @@ -9,19 +9,22 @@ import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.RedisClusterClient; import static org.junit.jupiter.api.Assertions.assertThrows; @Tag("integration") -public class JedisClusterPrefixedKeysTest extends PrefixedKeysTest { +public class RedisClusterPrefixedKeysTest extends PrefixedKeysTest { private static final JedisClientConfig CLIENT_CONFIG = DefaultJedisClientConfig.builder().password("cluster").build(); private static final Set NODES = HostAndPorts.getStableClusterServers().stream().collect(Collectors.toSet()); @Override - JedisCluster nonPrefixingJedis() { - return new JedisCluster(NODES, CLIENT_CONFIG); + RedisClusterClient nonPrefixingJedis() { + return RedisClusterClient.builder() + .nodes(NODES) + .clientConfig(CLIENT_CONFIG) + .build(); } @Override diff --git a/src/test/java/redis/clients/jedis/prefix/JedisSentineledPrefixedKeysTest.java b/src/test/java/redis/clients/jedis/prefix/RedisSentinelClientPrefixedKeysTest.java similarity index 66% rename from src/test/java/redis/clients/jedis/prefix/JedisSentineledPrefixedKeysTest.java rename to src/test/java/redis/clients/jedis/prefix/RedisSentinelClientPrefixedKeysTest.java index e66180ce83..ba567f0ca6 100644 --- a/src/test/java/redis/clients/jedis/prefix/JedisSentineledPrefixedKeysTest.java +++ b/src/test/java/redis/clients/jedis/prefix/RedisSentinelClientPrefixedKeysTest.java @@ -8,11 +8,11 @@ import redis.clients.jedis.HostAndPort; import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisSentineled; +import redis.clients.jedis.RedisSentinelClient; import org.junit.jupiter.api.Tag; @Tag("integration") -public class JedisSentineledPrefixedKeysTest extends PrefixedKeysTest { +public class RedisSentinelClientPrefixedKeysTest extends PrefixedKeysTest { private static final String MASTER_NAME = "mymaster"; private static final JedisClientConfig MASTER_CLIENT_CONFIG = DefaultJedisClientConfig.builder().password("foobared").build(); @@ -21,7 +21,12 @@ public class JedisSentineledPrefixedKeysTest extends PrefixedKeysTest