DATAREDIS-313 - Overhaul SCAN, HSCAN, SSCAN, ZSCAN operations.

Unify naming and return types.
Update supported commands documentation.
Remove key from BoundHashOperations and use getKey() instead.
Prevent error when trying to read values when there are no values present.
This commit is contained in:
Christoph Strobl
2014-06-06 07:54:23 +02:00
committed by Thomas Darimont
parent d8b53a4c96
commit 7b3a358752
2 changed files with 24 additions and 7 deletions

View File

@@ -3112,8 +3112,7 @@ public class LettuceConnection implements RedisConnection {
List<?> result = eval(script.getBytes(), ReturnType.MULTI, 0);
String nextCursorId = LettuceConverters.bytesToString().convert((byte[]) result.get(0));
@SuppressWarnings("unchecked")
Map<byte[], byte[]> values = LettuceConverters.toMap((List<byte[]>) result.get(1));
Map<byte[], byte[]> values = failsafeReadScanValues(result, LettuceConverters.bytesListToMapConverter());
return new ScanIteration<Entry<byte[], byte[]>>(Long.valueOf(nextCursorId), values.entrySet());
}
}.open();
@@ -3139,7 +3138,6 @@ public class LettuceConnection implements RedisConnection {
return new KeyBoundCursor<byte[]>(key, cursorId, options) {
@SuppressWarnings("unchecked")
@Override
protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions options) {
@@ -3154,7 +3152,8 @@ public class LettuceConnection implements RedisConnection {
List<?> result = eval(script.getBytes(), ReturnType.MULTI, 0);
String nextCursorId = LettuceConverters.bytesToString().convert((byte[]) result.get(0));
return new ScanIteration<byte[]>(Long.valueOf(nextCursorId), ((ArrayList<byte[]>) result.get(1)));
List<byte[]> values = failsafeReadScanValues(result, null);
return new ScanIteration<byte[]>(Long.valueOf(nextCursorId), values);
}
}.open();
}
@@ -3179,7 +3178,6 @@ public class LettuceConnection implements RedisConnection {
return new KeyBoundCursor<Tuple>(key, cursorId, options) {
@SuppressWarnings("unchecked")
@Override
protected ScanIteration<Tuple> doScan(byte[] key, long cursorId, ScanOptions options) {
@@ -3194,12 +3192,23 @@ public class LettuceConnection implements RedisConnection {
List<?> result = eval(script.getBytes(), ReturnType.MULTI, 0);
String nextCursorId = LettuceConverters.bytesToString().convert((byte[]) result.get(0));
return new ScanIteration<Tuple>(Long.valueOf(nextCursorId), LettuceConverters.toTuple((List<byte[]>) result
.get(1)));
List<Tuple> values = failsafeReadScanValues(result, LettuceConverters.bytesListToTupleListConverter());
return new ScanIteration<Tuple>(Long.valueOf(nextCursorId), values);
}
}.open();
}
@SuppressWarnings("unchecked")
private <T> T failsafeReadScanValues(List<?> source, @SuppressWarnings("rawtypes") Converter converter) {
try {
return (T) (converter != null ? converter.convert(source.get(1)) : source.get(1));
} catch (IndexOutOfBoundsException e) {
// ignore this one
}
return null;
}
/**
* Specifies if pipelined and transaction results should be converted to the expected data type. If false, results of
* {@link #closePipeline()} and {@link #exec()} will be of the type returned by the Lettuce driver

View File

@@ -174,6 +174,10 @@ abstract public class LettuceConverters extends Converters {
return BYTES_LIST_TO_TUPLE_LIST_CONVERTER.convert(list);
}
public static Converter<List<byte[]>, List<Tuple>> bytesListToTupleListConverter() {
return BYTES_LIST_TO_TUPLE_LIST_CONVERTER;
}
public static Converter<String, List<RedisClientInfo>> stringToRedisClientListConverter() {
return new Converter<String, List<RedisClientInfo>>() {
@@ -290,6 +294,10 @@ abstract public class LettuceConverters extends Converters {
return BYTES_LIST_TO_MAP.convert(source);
}
public static Converter<List<byte[]>, Map<byte[], byte[]>> bytesListToMapConverter() {
return BYTES_LIST_TO_MAP;
}
public static SortArgs toSortArgs(SortParameters params) {
SortArgs args = new SortArgs();
if (params == null) {