Merge pull request #537 from HeartSaVioR/deprecated_transactionblock_and_pipelineblock
Mark @Duplicated to TransactionBlock and PipelineBlock related classes / methods
This commit is contained in:
@@ -1696,6 +1696,13 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
|||||||
return new Transaction(client);
|
return new Transaction(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
/**
|
||||||
|
* This method is deprecated due to its error prone
|
||||||
|
* and will be removed on next major release
|
||||||
|
* You can use multi() instead
|
||||||
|
* @see https://github.com/xetorthio/jedis/pull/498
|
||||||
|
*/
|
||||||
public List<Object> multi(final TransactionBlock jedisTransaction) {
|
public List<Object> multi(final TransactionBlock jedisTransaction) {
|
||||||
List<Object> results = null;
|
List<Object> results = null;
|
||||||
jedisTransaction.setClient(client);
|
jedisTransaction.setClient(client);
|
||||||
@@ -2119,14 +2126,12 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
|||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
/**
|
/**
|
||||||
* Starts a pipeline, which is a very efficient way to send lots of command
|
* This method is deprecated due to its error prone with multi
|
||||||
* and read all the responses when you finish sending them. Try to avoid
|
* and will be removed on next major release
|
||||||
* this version and use pipelined() when possible as it will give better
|
* You can use pipelined() instead
|
||||||
* performance.
|
* @see https://github.com/xetorthio/jedis/pull/498
|
||||||
*
|
|
||||||
* @param jedisPipeline
|
|
||||||
* @return The results of the command in the same order you've run them.
|
|
||||||
*/
|
*/
|
||||||
public List<Object> pipelined(final PipelineBlock jedisPipeline) {
|
public List<Object> pipelined(final PipelineBlock jedisPipeline) {
|
||||||
jedisPipeline.setClient(client);
|
jedisPipeline.setClient(client);
|
||||||
|
|||||||
@@ -482,6 +482,12 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
/**
|
||||||
|
* This method is deprecated due to its error prone with multi
|
||||||
|
* and will be removed on next major release
|
||||||
|
* You can use pipelined() instead
|
||||||
|
* @see https://github.com/xetorthio/jedis/pull/498
|
||||||
|
*/
|
||||||
public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) {
|
public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) {
|
||||||
shardedJedisPipeline.setShardedJedis(this);
|
shardedJedisPipeline.setShardedJedis(this);
|
||||||
shardedJedisPipeline.execute();
|
shardedJedisPipeline.execute();
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
/**
|
||||||
|
* This method is deprecated due to its error prone with multi
|
||||||
|
* and will be removed on next major release
|
||||||
|
* @see https://github.com/xetorthio/jedis/pull/498
|
||||||
|
*/
|
||||||
public abstract class PipelineBlock extends Pipeline {
|
public abstract class PipelineBlock extends Pipeline {
|
||||||
public abstract void execute();
|
public abstract void execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ package redis.clients.jedis;
|
|||||||
|
|
||||||
import redis.clients.jedis.exceptions.JedisException;
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
/**
|
||||||
|
* This class is deprecated due to its error prone
|
||||||
|
* and will be removed on next major release
|
||||||
|
* @see https://github.com/xetorthio/jedis/pull/498
|
||||||
|
*/
|
||||||
public abstract class TransactionBlock extends Transaction {
|
public abstract class TransactionBlock extends Transaction {
|
||||||
public TransactionBlock(Client client) {
|
public TransactionBlock(Client client) {
|
||||||
super(client);
|
super(client);
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import org.junit.Test;
|
|||||||
import redis.clients.jedis.HostAndPort;
|
import redis.clients.jedis.HostAndPort;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.Pipeline;
|
import redis.clients.jedis.Pipeline;
|
||||||
import redis.clients.jedis.PipelineBlock;
|
|
||||||
import redis.clients.jedis.Response;
|
import redis.clients.jedis.Response;
|
||||||
import redis.clients.jedis.Tuple;
|
import redis.clients.jedis.Tuple;
|
||||||
import redis.clients.jedis.exceptions.JedisDataException;
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
@@ -35,21 +34,10 @@ public class PipeliningTest extends Assert {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pipeline() throws UnsupportedEncodingException {
|
public void pipeline() throws UnsupportedEncodingException {
|
||||||
List<Object> results = jedis.pipelined(new PipelineBlock() {
|
|
||||||
public void execute() {
|
|
||||||
set("foo", "bar");
|
|
||||||
get("foo");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
assertEquals(2, results.size());
|
|
||||||
assertEquals("OK", results.get(0));
|
|
||||||
assertEquals("bar", results.get(1));
|
|
||||||
|
|
||||||
Pipeline p = jedis.pipelined();
|
Pipeline p = jedis.pipelined();
|
||||||
p.set("foo", "bar");
|
p.set("foo", "bar");
|
||||||
p.get("foo");
|
p.get("foo");
|
||||||
results = p.syncAndReturnAll();
|
List<Object> results = p.syncAndReturnAll();
|
||||||
|
|
||||||
assertEquals(2, results.size());
|
assertEquals(2, results.size());
|
||||||
assertEquals("OK", results.get(0));
|
assertEquals("OK", results.get(0));
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ import redis.clients.jedis.Pipeline;
|
|||||||
import redis.clients.jedis.Protocol.Keyword;
|
import redis.clients.jedis.Protocol.Keyword;
|
||||||
import redis.clients.jedis.Response;
|
import redis.clients.jedis.Response;
|
||||||
import redis.clients.jedis.Transaction;
|
import redis.clients.jedis.Transaction;
|
||||||
import redis.clients.jedis.TransactionBlock;
|
|
||||||
import redis.clients.jedis.exceptions.JedisDataException;
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
import redis.clients.jedis.exceptions.JedisException;
|
|
||||||
|
|
||||||
public class TransactionCommandsTest extends JedisCommandTestBase {
|
public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
@@ -73,87 +71,6 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void multiBlock() {
|
|
||||||
List<Object> response = jedis.multi(new TransactionBlock() {
|
|
||||||
@Override
|
|
||||||
public void execute() {
|
|
||||||
sadd("foo", "a");
|
|
||||||
sadd("foo", "b");
|
|
||||||
scard("foo");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
List<Object> expected = new ArrayList<Object>();
|
|
||||||
expected.add(1L);
|
|
||||||
expected.add(1L);
|
|
||||||
expected.add(2L);
|
|
||||||
assertEquals(expected, response);
|
|
||||||
|
|
||||||
// Binary
|
|
||||||
response = jedis.multi(new TransactionBlock() {
|
|
||||||
@Override
|
|
||||||
public void execute() {
|
|
||||||
sadd(bfoo, ba);
|
|
||||||
sadd(bfoo, bb);
|
|
||||||
scard(bfoo);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
expected = new ArrayList<Object>();
|
|
||||||
expected.add(1L);
|
|
||||||
expected.add(1L);
|
|
||||||
expected.add(2L);
|
|
||||||
assertEquals(expected, response);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void multiBlockWithErrorRedisDiscardsTransaction() throws Exception {
|
|
||||||
// Transaction with error - Redis discards transaction automatically
|
|
||||||
// (Syntax Error, etc.)
|
|
||||||
TransactionBlock tb = new TransactionBlock() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute() throws JedisException {
|
|
||||||
del("hello");
|
|
||||||
hmset("hello", new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
jedis.multi(tb);
|
|
||||||
} catch (JedisDataException e) {
|
|
||||||
assertTrue(e.getMessage().contains("EXECABORT"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void multiBlockWithErrorRedisForceToExecuteAllCommands()
|
|
||||||
throws Exception {
|
|
||||||
// Transaction with error - Redis doesn't roll back (Type Error,
|
|
||||||
// Deletion of non-exist key, etc.)
|
|
||||||
jedis.del("hello2");
|
|
||||||
TransactionBlock tb2 = new TransactionBlock() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute() throws JedisException {
|
|
||||||
del("hello2");
|
|
||||||
set("hello2", "hello");
|
|
||||||
sadd("hello2", "hello2");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
List<Object> responses = jedis.multi(tb2);
|
|
||||||
assertEquals("OK", responses.get(1));
|
|
||||||
assertEquals(JedisDataException.class, responses.get(2).getClass());
|
|
||||||
|
|
||||||
Exception exc = (JedisDataException) responses.get(2);
|
|
||||||
assertTrue(exc.getMessage().contains("WRONGTYPE"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void watch() throws UnknownHostException, IOException {
|
public void watch() throws UnknownHostException, IOException {
|
||||||
jedis.watch("mykey", "somekey");
|
jedis.watch("mykey", "somekey");
|
||||||
|
|||||||
Reference in New Issue
Block a user