From 55e77b5c2d7734f736e25827ab1f62ca4cf4f2e1 Mon Sep 17 00:00:00 2001 From: Andrew Kolpakov Date: Thu, 20 Nov 2014 18:18:21 +0600 Subject: [PATCH] fastRemove shouldn't call server with empty argument list, getAll shouldn't return missing keys --- src/main/java/org/redisson/RedissonMap.java | 30 +++++++++++-------- .../java/org/redisson/RedissonMapTest.java | 9 +++++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/redisson/RedissonMap.java b/src/main/java/org/redisson/RedissonMap.java index be7bcfd8e..d8dbd1041 100644 --- a/src/main/java/org/redisson/RedissonMap.java +++ b/src/main/java/org/redisson/RedissonMap.java @@ -19,13 +19,7 @@ import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Promise; import java.math.BigDecimal; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; +import java.util.*; import org.redisson.async.AsyncOperation; import org.redisson.async.OperationListener; @@ -93,6 +87,9 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public Map getAll(final Set keys) { + if (keys.size() == 0) { + return Collections.emptyMap(); + } List list = connectionManager.read(new ResultOperation, V>() { @Override protected Future> execute(RedisAsyncConnection async) { @@ -104,6 +101,9 @@ public class RedissonMap extends RedissonExpirable implements RMap { int index = 0; for (K key : keys) { V value = list.get(index); + if (value == null) { + continue; + } result.put(key, value); index++; } @@ -442,12 +442,16 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public Future fastRemoveAsync(final K ... keys) { - return connectionManager.writeAsync(new ResultOperation() { - @Override - public Future execute(RedisAsyncConnection async) { - return async.hdel(getName(), keys); - } - }); + if (keys != null && keys.length > 0) { + return connectionManager.writeAsync(new ResultOperation() { + @Override + public Future execute(RedisAsyncConnection async) { + return async.hdel(getName(), keys); + } + }); + } else { + return connectionManager.getGroup().next().newSucceededFuture(0L); + } } @Override diff --git a/src/test/java/org/redisson/RedissonMapTest.java b/src/test/java/org/redisson/RedissonMapTest.java index c4ded1535..51fbe068b 100644 --- a/src/test/java/org/redisson/RedissonMapTest.java +++ b/src/test/java/org/redisson/RedissonMapTest.java @@ -136,7 +136,7 @@ public class RedissonMapTest extends BaseTest { map.put(3, 300); map.put(4, 400); - Map filtered = map.getAll(new HashSet(Arrays.asList(2, 3))); + Map filtered = map.getAll(new HashSet(Arrays.asList(2, 3, 5))); Map expectedMap = new HashMap(); expectedMap.put(2, 200); @@ -431,4 +431,11 @@ public class RedissonMapTest extends BaseTest { Assert.assertEquals(1, map.size()); } + @Test + public void testFastRemoveEmpty() throws Exception { + RMap map = redisson.getMap("simple"); + map.put(1, 3); + Assert.assertEquals(0, map.fastRemove()); + Assert.assertEquals(1, map.size()); + } }