RMap.putAll fixed. #265

pull/282/head
Nikita 9 years ago
parent b12f49b416
commit 4ef7df4d4f

@ -148,12 +148,23 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
}
@Override
public void putAll(final Map<? extends K, ? extends V> map) {
if (map.size() == 0) {
return;
public void putAll(Map<? extends K, ? extends V> map) {
get(putAllAsync(map));
}
public Future<Void> putAllAsync(Map<? extends K, ? extends V> map) {
if (map.isEmpty()) {
return newSucceededFuture(null);
}
List<Object> params = new ArrayList<Object>(map.size()*2 + 1);
params.add(getName());
for (java.util.Map.Entry<? extends K, ? extends V> t : map.entrySet()) {
params.add(t.getKey());
params.add(t.getValue());
}
commandExecutor.write(getName(), codec, RedisCommands.HMSET, getName(), map);
return commandExecutor.writeAsync(getName(), codec, RedisCommands.HMSET, params.toArray());
}
@Override

@ -52,6 +52,10 @@ abstract class RedissonObject implements RObject {
return commandExecutor.getConnectionManager().getGroup().next().<V>newPromise();
}
protected <V> Future<V> newSucceededFuture(V result) {
return commandExecutor.getConnectionManager().getGroup().next().<V>newSucceededFuture(result);
}
@Override
public String getName() {
return name;

@ -150,7 +150,7 @@ public interface RedisCommands {
RedisCommand<Boolean> HEXISTS = new RedisCommand<Boolean>("HEXISTS", new BooleanReplayConvertor(), 2, ValueType.MAP_KEY);
RedisStrictCommand<Integer> HLEN = new RedisStrictCommand<Integer>("HLEN", new IntegerReplayConvertor());
RedisCommand<Set<Object>> HKEYS = new RedisCommand<Set<Object>>("HKEYS", new ObjectSetReplayDecoder(), ValueType.MAP_KEY);
RedisCommand<String> HMSET = new RedisCommand<String>("HMSET", new StringReplayDecoder(), 1, ValueType.MAP);
RedisCommand<String> HMSET = new RedisCommand<String>("HMSET", new StringReplayDecoder(), 2, ValueType.MAP);
RedisCommand<List<Object>> HMGET = new RedisCommand<List<Object>>("HMGET", new ObjectListReplayDecoder<Object>(), 2, ValueType.MAP_KEY, ValueType.MAP_VALUE);
RedisCommand<Object> HGET = new RedisCommand<Object>("HGET", 2, ValueType.MAP_KEY, ValueType.MAP_VALUE);
RedisCommand<Long> HDEL = new RedisStrictCommand<Long>("HDEL", 2, ValueType.MAP_KEY);

@ -16,6 +16,7 @@
package org.redisson.core;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import io.netty.util.concurrent.Future;
@ -30,6 +31,8 @@ import io.netty.util.concurrent.Future;
*/
public interface RMapAsync<K, V> extends RExpirableAsync {
Future<Void> putAllAsync(Map<? extends K, ? extends V> map);
Future<V> addAndGetAsync(K key, Number value);
Future<Collection<V>> valuesAsync();

@ -277,6 +277,22 @@ public class RedissonMapTest extends BaseTest {
Assert.assertEquals(1, map.size());
}
@Test
public void testPutAll() {
Map<Integer, String> map = redisson.getMap("simple");
map.put(1, "1");
map.put(2, "2");
map.put(3, "3");
Map<Integer, String> joinMap = new HashMap<Integer, String>();
joinMap.put(4, "4");
joinMap.put(5, "5");
joinMap.put(6, "6");
map.putAll(joinMap);
MatcherAssert.assertThat(map.keySet(), Matchers.containsInAnyOrder(1, 2, 3, 4, 5, 6));
}
@Test
public void testKeySet() {
Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");

Loading…
Cancel
Save