Lettuce closePipeline should return List of tx results

and strip individual op results

DATAREDIS-223
This commit is contained in:
Jennifer Hickey
2013-07-18 15:28:55 -07:00
parent 136ad487a8
commit a0b4613a4b
16 changed files with 243 additions and 372 deletions

View File

@@ -185,7 +185,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
public List<Object> exec() {
List<Object> results = delegate.exec();
if(isPipelined()) {
pipeline(identityConverter(results));
// Ensure exec converter gets added
pipelineConverters.add(identityConverter(results));
}
return results;
}
@@ -2188,6 +2189,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
}
private void pipeline(Converter<?,?> converter) {
pipelineConverters.add(converter);
if(!isQueueing()) {
pipelineConverters.add(converter);
}
}
}

View File

@@ -572,14 +572,10 @@ public class LettuceConnection implements RedisConnection {
isMulti = false;
try {
if (isPipelined()) {
getAsyncDedicatedConnection().exec();
pipeline(new LettuceResult(getAsyncDedicatedConnection().exec(), LettuceConverters.execResultsConverter()));
return null;
}
List<Object> results = getDedicatedConnection().exec();
if (results.isEmpty()) {
return null;
}
return results;
return LettuceConverters.toExecResults(getDedicatedConnection().exec());
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
@@ -704,7 +700,7 @@ public class LettuceConnection implements RedisConnection {
isMulti = true;
try {
if (isPipelined()) {
pipeline(new LettuceStatusResult(getAsyncDedicatedConnection().multi()));
getAsyncDedicatedConnection().multi();
return;
}
getDedicatedConnection().multi();
@@ -2219,8 +2215,10 @@ public class LettuceConnection implements RedisConnection {
}
private void pipeline(LettuceResult result) {
// the future will always be a command plus it throws no exception on #get
ppline.add(result);
if(!isQueueing()) {
// Don't add individual tx op results to pipeline
ppline.add(result);
}
}
private RedisAsyncConnection<byte[], byte[]> getAsyncConnection() {

View File

@@ -59,6 +59,7 @@ abstract public class LettuceConverters extends Converters {
private static final Converter<KeyValue<byte[], byte[]>, List<byte[]>> KEY_VALUE_TO_BYTES_LIST;
private static final Converter<List<ScoredValue<byte[]>>, Set<Tuple>> SCORED_VALUES_TO_TUPLE_SET;
private static final Converter<ScoredValue<byte[]>, Tuple> SCORED_VALUE_TO_TUPLE;
private static final Converter<List<Object>, List<Object>> EXEC_RESULTS_CONVERTER;
static {
DATE_TO_LONG = new Converter<Date, Long>() {
@@ -107,6 +108,16 @@ abstract public class LettuceConverters extends Converters {
}
};
EXEC_RESULTS_CONVERTER = new Converter<List<Object>, List<Object>>() {
public List<Object> convert(List<Object> source) {
// Lettuce Empty list means null (watched variable modified)
if(source.isEmpty()) {
return null;
}
return source;
}
};
}
public static Converter<Date, Long> dateToLong() {
@@ -133,6 +144,10 @@ abstract public class LettuceConverters extends Converters {
return SCORED_VALUE_TO_TUPLE;
}
public static Converter<List<Object>, List<Object>> execResultsConverter() {
return EXEC_RESULTS_CONVERTER;
}
public static Long toLong(Date source) {
return DATE_TO_LONG.convert(source);
}
@@ -230,4 +245,8 @@ abstract public class LettuceConverters extends Converters {
}
return args;
}
public static List<Object> toExecResults(List<Object> source) {
return EXEC_RESULTS_CONVERTER.convert(source);
}
}