DATAREDIS-289 - Avoid NPE in DefaultValueOperations#append() in case of pipelining or/and multi/exec calls.
We now return null if DefaultValueOperations#append() was applied to a non-existing list and thus returned null. Previously a NPE was thrown in case of pipelining or/and multi/exec calls. Original pull request: #48.
This commit is contained in:
@@ -83,7 +83,8 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
|
||||
return execute(new RedisCallback<Integer>() {
|
||||
|
||||
public Integer doInRedis(RedisConnection connection) {
|
||||
return connection.append(rawKey, rawString).intValue();
|
||||
final Long result = connection.append(rawKey, rawString);
|
||||
return ( result != null ) ? result.intValue() : null;
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
@@ -221,6 +221,7 @@ public class RedisTemplateTests<K, V> {
|
||||
operations.multi();
|
||||
operations.opsForValue().set("foo", "5");
|
||||
operations.opsForValue().get("foo");
|
||||
operations.opsForValue().append("foo1", "5");
|
||||
operations.opsForList().leftPush("foolist", "6");
|
||||
operations.opsForList().range("foolist", 0l, 1l);
|
||||
operations.opsForSet().add("fooset", "7");
|
||||
@@ -242,7 +243,7 @@ public class RedisTemplateTests<K, V> {
|
||||
Map<Long, Long> map = new LinkedHashMap<Long, Long>();
|
||||
map.put(10l, 11l);
|
||||
assertThat(results,
|
||||
isEqual(Arrays.asList(new Object[] { 5l, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map })));
|
||||
isEqual(Arrays.asList(new Object[] { 5l, 1L, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map })));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user