Fixed - `RMultimap.sizeInMemory()` method doesn't take in account size of all associated objects #3034

pull/3048/head
Nikita Koksharov 4 years ago
parent 093d078615
commit e36d2097bb

@ -54,6 +54,20 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
prefix = suffixName(getName(), "");
}
@Override
public RFuture<Long> sizeInMemoryAsync() {
return commandExecutor.evalWriteAsync(getName(), StringCodec.INSTANCE, RedisCommands.EVAL_LONG,
"local keys = redis.call('hgetall', KEYS[1]); " +
"local size = 0; " +
"for i, v in ipairs(keys) do " +
"if i % 2 == 0 then " +
"local name = ARGV[1] .. v; " +
"size = size + redis.call('memory', 'usage', name); " +
"end;" +
"end; " +
"return size; ", Arrays.asList(getName()), prefix);
}
@Override
public RLock getFairLock(K key) {
String lockName = getLockByMapKey(key, "fairlock");

@ -3,6 +3,7 @@ package org.redisson;
import org.junit.Test;
import org.redisson.api.RList;
import org.redisson.api.RListMultimap;
import org.redisson.api.RSetMultimap;
import java.io.Serializable;
import java.util.*;
@ -113,6 +114,16 @@ public class RedissonListMultimapTest extends BaseTest {
}
@Test
public void testSizeInMemory() {
RListMultimap<String, String> list = redisson.getListMultimap("test");
list.put("1", "2");
assertThat(list.sizeInMemory()).isEqualTo(160);
list.put("1", "3");
assertThat(list.sizeInMemory()).isEqualTo(166);
}
@Test
public void testDelete() {
RListMultimap<String, String> testList = redisson.getListMultimap( "test" );

@ -214,6 +214,15 @@ public class RedissonSetMultimapTest extends BaseTest {
assertThat(multimap1.keySize()).isEqualTo(0);
}
@Test
public void testSizeInMemory() {
RSetMultimap<String, String> set = redisson.getSetMultimap("test");
set.put("1", "2");
assertThat(set.sizeInMemory()).isEqualTo(229);
set.put("1", "3");
assertThat(set.sizeInMemory()).isEqualTo(259);
}
@Test
public void testSize() {

Loading…
Cancel
Save