From 927af25ba9f4287a70cf4df4daef340974e6d83c Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Mon, 30 Oct 2023 17:20:18 +0600 Subject: [PATCH] Return MultiClusterTransaction from UnifiedJedis --- src/main/java/redis/clients/jedis/UnifiedJedis.java | 5 ++++- .../jedis/activeactive/MultiClusterTransaction.java | 8 +++++--- .../commands/unified/pooled/PooledMiscellaneousTest.java | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 70a0651003..c5a54e31c3 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -10,6 +10,7 @@ import java.util.regex.Pattern; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.json.JSONArray; +import redis.clients.jedis.activeactive.MultiClusterTransaction; import redis.clients.jedis.args.*; import redis.clients.jedis.bloom.*; @@ -4831,9 +4832,11 @@ public PipelineBase pipelined() { } } - public Transaction multi() { + public TransactionBase multi() { if (provider == null) { throw new IllegalStateException("It is not allowed to create Pipeline from this " + getClass()); + } else if (provider instanceof MultiClusterPooledConnectionProvider) { + return new MultiClusterTransaction((MultiClusterPooledConnectionProvider) provider); } return new Transaction(provider.getConnection(), true, true); } diff --git a/src/main/java/redis/clients/jedis/activeactive/MultiClusterTransaction.java b/src/main/java/redis/clients/jedis/activeactive/MultiClusterTransaction.java index 08f60cfdad..8cde059ea9 100644 --- a/src/main/java/redis/clients/jedis/activeactive/MultiClusterTransaction.java +++ b/src/main/java/redis/clients/jedis/activeactive/MultiClusterTransaction.java @@ -16,6 +16,7 @@ import redis.clients.jedis.*; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.graph.ResultSet; +import redis.clients.jedis.providers.MultiClusterPooledConnectionProvider; import redis.clients.jedis.util.KeyValue; /** @@ -37,7 +38,7 @@ public class MultiClusterTransaction extends TransactionBase { * called with this object. * @param provider */ - public MultiClusterTransaction(CircuitBreakerFailoverConnectionProvider provider) { + public MultiClusterTransaction(MultiClusterPooledConnectionProvider provider) { this(provider, true); } @@ -48,13 +49,14 @@ public MultiClusterTransaction(CircuitBreakerFailoverConnectionProvider provider * @param provider * @param doMulti {@code false} should be set to enable manual WATCH, UNWATCH and MULTI */ - public MultiClusterTransaction(CircuitBreakerFailoverConnectionProvider provider, boolean doMulti) { + public MultiClusterTransaction(MultiClusterPooledConnectionProvider provider, boolean doMulti) { try (Connection connection = provider.getConnection()) { // we don't need a healthy connection now RedisProtocol proto = connection.getRedisProtocol(); if (proto != null) this.commandObjects.setProtocol(proto); } - this.provider = provider; + this.provider = new CircuitBreakerFailoverConnectionProvider(provider); + if (doMulti) multi(); } diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java index 230d9d184b..64a7978ad1 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java @@ -15,14 +15,14 @@ import redis.clients.jedis.JedisPooled; import redis.clients.jedis.Pipeline; import redis.clients.jedis.Response; -import redis.clients.jedis.Transaction; +import redis.clients.jedis.TransactionBase; import redis.clients.jedis.commands.unified.UnifiedJedisCommandsTestBase; import redis.clients.jedis.exceptions.JedisDataException; public class PooledMiscellaneousTest extends UnifiedJedisCommandsTestBase { protected Pipeline pipeline; - protected Transaction transaction; + protected TransactionBase transaction; @BeforeClass public static void prepare() throws InterruptedException {