Skip to content

Commit

Permalink
Return MultiClusterTransaction from UnifiedJedis
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Oct 30, 2023
1 parent 2e87a2c commit 927af25
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
}

Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 927af25

Please sign in to comment.