Merge pull request #189 from vsoskov/jedis
--- the exception is returned in the list with the not formatted and formatted values. Response.get throws the exception.
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
|
||||||
public class BinaryTransaction extends Queable {
|
public class BinaryTransaction extends Queable {
|
||||||
protected Client client = null;
|
protected Client client = null;
|
||||||
@@ -28,10 +29,29 @@ public class BinaryTransaction extends Queable {
|
|||||||
}
|
}
|
||||||
List<Object> formatted = new ArrayList<Object>();
|
List<Object> formatted = new ArrayList<Object>();
|
||||||
for (Object o : unformatted) {
|
for (Object o : unformatted) {
|
||||||
formatted.add(generateResponse(o).get());
|
try{
|
||||||
|
formatted.add(generateResponse(o).get());
|
||||||
|
}catch(JedisDataException e){
|
||||||
|
formatted.add(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Response<?>> execGetResponse() {
|
||||||
|
client.exec();
|
||||||
|
client.getAll(1); // Discard all but the last reply
|
||||||
|
|
||||||
|
List<Object> unformatted = client.getObjectMultiBulkReply();
|
||||||
|
if (unformatted == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<Response<?>> response = new ArrayList<Response<?>>();
|
||||||
|
for (Object o : unformatted) {
|
||||||
|
response.add(generateResponse(o));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
public String discard() {
|
public String discard() {
|
||||||
client.discard();
|
client.discard();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import redis.clients.jedis.Protocol.Command;
|
import redis.clients.jedis.Protocol.Command;
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
import redis.clients.jedis.exceptions.JedisException;
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
import redis.clients.util.RedisInputStream;
|
import redis.clients.util.RedisInputStream;
|
||||||
import redis.clients.util.RedisOutputStream;
|
import redis.clients.util.RedisOutputStream;
|
||||||
@@ -213,7 +214,11 @@ public class Connection {
|
|||||||
List<Object> all = new ArrayList<Object>();
|
List<Object> all = new ArrayList<Object>();
|
||||||
flush();
|
flush();
|
||||||
while (pipelinedCommands > except) {
|
while (pipelinedCommands > except) {
|
||||||
all.add(protocol.read(inputStream));
|
try{
|
||||||
|
all.add(protocol.read(inputStream));
|
||||||
|
}catch(JedisDataException e){
|
||||||
|
all.add(e);
|
||||||
|
}
|
||||||
pipelinedCommands--;
|
pipelinedCommands--;
|
||||||
}
|
}
|
||||||
return all;
|
return all;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
|
||||||
public class Pipeline extends Queable {
|
public class Pipeline extends Queable {
|
||||||
private Client client;
|
private Client client;
|
||||||
@@ -39,7 +40,11 @@ public class Pipeline extends Queable {
|
|||||||
List<Object> unformatted = client.getAll();
|
List<Object> unformatted = client.getAll();
|
||||||
List<Object> formatted = new ArrayList<Object>();
|
List<Object> formatted = new ArrayList<Object>();
|
||||||
for (Object o : unformatted) {
|
for (Object o : unformatted) {
|
||||||
formatted.add(generateResponse(o).get());
|
try{
|
||||||
|
formatted.add(generateResponse(o).get());
|
||||||
|
}catch(JedisDataException e){
|
||||||
|
formatted.add(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,11 @@ public final class Protocol {
|
|||||||
}
|
}
|
||||||
List<Object> ret = new ArrayList<Object>(num);
|
List<Object> ret = new ArrayList<Object>(num);
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
ret.add(process(is));
|
try{
|
||||||
|
ret.add(process(is));
|
||||||
|
}catch(JedisDataException e){
|
||||||
|
ret.add(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ public class Response<T> {
|
|||||||
"Please close pipeline or multi block before calling this method.");
|
"Please close pipeline or multi block before calling this method.");
|
||||||
}
|
}
|
||||||
if (!built) {
|
if (!built) {
|
||||||
|
if (data instanceof JedisDataException){
|
||||||
|
throw new JedisDataException((JedisDataException)data);
|
||||||
|
}
|
||||||
response = builder.build(data);
|
response = builder.build(data);
|
||||||
this.data = null;
|
this.data = null;
|
||||||
built = true;
|
built = true;
|
||||||
|
|||||||
@@ -118,4 +118,20 @@ public class PipeliningTest extends Assert {
|
|||||||
p.sync();
|
p.sync();
|
||||||
assertNull(shouldNotExist.get());
|
assertNull(shouldNotExist.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void piplineWithError(){
|
||||||
|
Pipeline p = jedis.pipelined();
|
||||||
|
p.set("foo", "bar");
|
||||||
|
Response<Set<String>> error = p.smembers("foo");
|
||||||
|
Response<String> r = p.get("foo");
|
||||||
|
p.sync();
|
||||||
|
try{
|
||||||
|
error.get();
|
||||||
|
fail();
|
||||||
|
}catch(JedisDataException e){
|
||||||
|
//that is fine we should be here
|
||||||
|
}
|
||||||
|
assertEquals(r.get(), "bar");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
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.TransactionBlock;
|
||||||
@@ -241,4 +242,39 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
string.get();
|
string.get();
|
||||||
t.exec();
|
t.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void transactionResponseWithError() {
|
||||||
|
Transaction t = jedis.multi();
|
||||||
|
t.set("foo", "bar");
|
||||||
|
Response<Set<String>> error = t.smembers("foo");
|
||||||
|
Response<String> r = t.get("foo");
|
||||||
|
List<Object> l = t.exec();
|
||||||
|
assertEquals(JedisDataException.class, l.get(1).getClass());
|
||||||
|
try{
|
||||||
|
error.get();
|
||||||
|
fail("We expect exception here!");
|
||||||
|
}catch(JedisDataException e){
|
||||||
|
//that is fine we should be here
|
||||||
|
}
|
||||||
|
assertEquals(r.get(), "bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void execGetResponse() {
|
||||||
|
Transaction t = jedis.multi();
|
||||||
|
|
||||||
|
t.set("foo", "bar");
|
||||||
|
t.smembers("foo");
|
||||||
|
t.get("foo");
|
||||||
|
|
||||||
|
List<Response<?>> lr = t.execGetResponse();
|
||||||
|
try{
|
||||||
|
lr.get(1).get();
|
||||||
|
fail("We expect exception here!");
|
||||||
|
}catch(JedisDataException e){
|
||||||
|
//that is fine we should be here
|
||||||
|
}
|
||||||
|
assertEquals("bar", lr.get(2).get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user