RMapCache.putAll couldn't handle map with entries amount larger than 5000. #951

pull/1025/head
Nikita 8 years ago
parent 907f180ac3
commit 2bdccfccf1

@ -1291,7 +1291,11 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
}
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_VOID,
"for i, value in ipairs(ARGV) do "
"for i=1, #ARGV, 5000 do "
+ "redis.call('hmset', KEYS[1], unpack(ARGV, i, math.min(i+4999, table.getn(ARGV)))) "
+ "end; "
+ "for i, value in ipairs(ARGV) do "
+ "if i % 2 == 0 then "
+ "local val = struct.pack('dLc0', 0, string.len(value), value); "
+ "ARGV[i] = val; "
@ -1300,8 +1304,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+ "local msg = struct.pack('Lc0Lc0', string.len(key), key, string.len(value), value); "
+ "redis.call('publish', KEYS[2], msg); "
+ "end;"
+ "end;"
+ "return redis.call('hmset', KEYS[1], unpack(ARGV)); ",
+ "end;",
Arrays.<Object>asList(getName(), getCreatedChannelName()), params.toArray());
}

@ -432,6 +432,19 @@ public class RedissonMapCacheTest extends BaseMapTest {
Assert.assertEquals(1, map.size());
}
@Test
public void testPutAllBig() {
Map<Integer, String> joinMap = new HashMap<Integer, String>();
for (int i = 0; i < 100000; i++) {
joinMap.put(i, "" + i);
}
Map<Integer, String> map = redisson.getMapCache("simple");
map.putAll(joinMap);
assertThat(map.size()).isEqualTo(joinMap.size());
}
@Test
public void testPutAll() {
Map<Integer, String> map = redisson.getMapCache("simple");

Loading…
Cancel
Save