DATAKV-34
+ improve handling of collections during pipeline/multi operations
This commit is contained in:
@@ -594,6 +594,10 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
|
||||
|
||||
private List<String> deserialize(Collection<byte[]> data) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> result = new ArrayList<String>(data.size());
|
||||
for (byte[] raw : data) {
|
||||
result.add(serializer.deserialize(raw));
|
||||
@@ -602,6 +606,10 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
}
|
||||
|
||||
private Set<String> deserialize(Set<byte[]> data) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<String> result = new LinkedHashSet<String>(data.size());
|
||||
for (byte[] raw : data) {
|
||||
result.add(serializer.deserialize(raw));
|
||||
@@ -614,6 +622,9 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
}
|
||||
|
||||
private Set<StringTuple> deserializeTuple(Set<Tuple> data) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
Set<StringTuple> result = new LinkedHashSet<StringTuple>(data.size());
|
||||
for (Tuple raw : data) {
|
||||
result.add(new DefaultStringTuple(raw, serializer.deserialize(raw.getValue())));
|
||||
|
||||
@@ -146,6 +146,11 @@ abstract class AbstractOperations<K, V> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<HK, HV> Map<HK, HV> deserializeHashMap(Map<byte[], byte[]> entries) {
|
||||
// connection in pipeline/multi mode
|
||||
if (entries == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<HK, HV> map = new LinkedHashMap<HK, HV>(entries.size());
|
||||
|
||||
for (Map.Entry<byte[], byte[]> entry : entries.entrySet()) {
|
||||
|
||||
@@ -39,6 +39,11 @@ public abstract class SerializationUtils {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T extends Collection<?>> T deserializeValues(Collection<byte[]> rawValues, Class<T> type, RedisSerializer<?> redisSerializer) {
|
||||
// connection in pipeline/multi mode
|
||||
if (rawValues == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collection<Object> values = (List.class.isAssignableFrom(type) ? new ArrayList<Object>(rawValues.size())
|
||||
: new LinkedHashSet<Object>(rawValues.size()));
|
||||
for (byte[] bs : rawValues) {
|
||||
|
||||
@@ -162,4 +162,12 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
assertNull(multiGet.get(0));
|
||||
assertNull(multiGet.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullCollections() throws Exception {
|
||||
connection.openPipeline();
|
||||
assertNull(connection.keys("~*"));
|
||||
assertNull(connection.hKeys("~"));
|
||||
connection.closePipeline();
|
||||
}
|
||||
}
|
||||
@@ -70,4 +70,8 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
@Ignore("JRedis has connecting issues with null")
|
||||
public void testNullKey() {
|
||||
}
|
||||
|
||||
@Ignore("JRedis does not support pipelining")
|
||||
public void testNullCollections() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user