Fixed - method containsAll execute incorrect or caused RedisException

Signed-off-by: seakider <seakider@gmail.com>
pull/6006/head
seakider 7 months ago
parent fc59b0785d
commit 2491156c1a

@ -139,7 +139,7 @@ public class BaseRedissonList<V> extends RedissonExpirable {
return commandExecutor.evalReadAsync(getRawName(), codec, RedisCommands.EVAL_BOOLEAN,
"local items = redis.call('lrange', KEYS[1], 0, -1) " +
"for i=1, #items do " +
"for j = 1, #ARGV, 1 do " +
"for j = #ARGV, 1, -1 do " +
"if items[i] == ARGV[j] then " +
"table.remove(ARGV, j) " +
"end " +

@ -320,7 +320,7 @@ public class RedissonDelayedQueue<V> extends RedissonExpirable implements RDelay
+ "local v = redis.call('lindex', KEYS[1], i);"
+ "local randomId, value = struct.unpack('Bc0Lc0', v);"
+ "for j = 1, #ARGV, 1 do "
+ "for j = #ARGV, 1, -1 do "
+ "if value == ARGV[j] then "
+ "table.remove(ARGV, j) "
+ "end; "

@ -232,7 +232,7 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
+ "end; " +
"local items = redis.call('lrange', KEYS[2], 0, -1);" +
"for i = 1, #items, 1 do " +
"for j = 2, #ARGV, 1 do "
"for j = #ARGV, 3, -1 do "
+ "if ARGV[j] == items[i] "
+ "then table.remove(ARGV, j) end "
+ "end; "
@ -285,7 +285,7 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
+ "end; " +
"local v = 0 " +
"for i = 2, #ARGV, 1 do "
"for i = 3, #ARGV, 1 do "
+ "if redis.call('lrem', KEYS[2], 0, ARGV[i]) == 1 "
+ "then v = 1 end "
+"end "
@ -326,7 +326,7 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
+ "while i <= #s do "
+ "local element = s[i]; "
+ "local isInAgrs = false; "
+ "for j = 2, #ARGV, 1 do "
+ "for j = 3, #ARGV, 1 do "
+ "if ARGV[j] == element then "
+ "isInAgrs = true; "
+ "break; "

@ -454,7 +454,7 @@ public class RedissonSetMultimapValues<V> extends RedissonExpirable implements R
+ "end; " +
"local s = redis.call('smembers', KEYS[2]);" +
"for i = 1, #s, 1 do " +
"for j = 2, #ARGV, 1 do "
"for j = #ARGV, 3, -1 do "
+ "if ARGV[j] == s[i] "
+ "then table.remove(ARGV, j) end "
+ "end; "
@ -536,7 +536,7 @@ public class RedissonSetMultimapValues<V> extends RedissonExpirable implements R
+ "while i <= #s do "
+ "local element = s[i] "
+ "local isInAgrs = false "
+ "for j = 2, #ARGV, 1 do "
+ "for j = 3, #ARGV, 1 do "
+ "if ARGV[j] == element then "
+ "isInAgrs = true "
+ "break "
@ -570,7 +570,7 @@ public class RedissonSetMultimapValues<V> extends RedissonExpirable implements R
+ "end; " +
"local v = 0 " +
"for i = 2, #ARGV, 1 do "
"for i = 3, #ARGV, 1 do "
+ "if redis.call('srem', KEYS[2], ARGV[i]) == 1 "
+ "then v = 1 end "
+"end "

@ -87,10 +87,10 @@ public class RedissonSubList<V> extends RedissonList<V> implements RList<V> {
encode(params, c);
return commandExecutor.evalReadAsync(getRawName(), codec, RedisCommands.EVAL_BOOLEAN,
"local fromIndex = table.remove(ARGV, 1);" +
"local toIndex = table.remove(ARGV, 2);" +
"local toIndex = table.remove(ARGV, 1);" +
"local items = redis.call('lrange', KEYS[1], tonumber(fromIndex), tonumber(toIndex)) " +
"for i=1, #items do " +
"for j = 1, #ARGV, 1 do " +
"for j = #ARGV, 1, -1 do " +
"if items[i] == ARGV[j] then " +
"table.remove(ARGV, j) " +
"end " +
@ -163,7 +163,7 @@ public class RedissonSubList<V> extends RedissonList<V> implements RList<V> {
return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_BOOLEAN,
"local v = 0; " +
"local fromIndex = table.remove(ARGV, 1);" +
"local toIndex = table.remove(ARGV, 2);" +
"local toIndex = table.remove(ARGV, 1);" +
"local count = table.remove(ARGV, 3);" +
"local items = redis.call('lrange', KEYS[1], fromIndex, toIndex); " +
@ -189,7 +189,7 @@ public class RedissonSubList<V> extends RedissonList<V> implements RList<V> {
return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_BOOLEAN,
"local changed = 0 " +
"local fromIndex = table.remove(ARGV, 1);" +
"local toIndex = table.remove(ARGV, 2);" +
"local toIndex = table.remove(ARGV, 1);" +
"local items = redis.call('lrange', KEYS[1], fromIndex, toIndex) "
+ "local i = 1 "
+ "while i <= #items do "

@ -105,7 +105,10 @@ public class RedissonDelayedQueueTest extends RedisDockerTest {
assertThat(dealyedQueue.containsAll(Arrays.asList(1, 2))).isTrue();
assertThat(dealyedQueue.containsAll(Arrays.asList(1, 2, 4))).isFalse();
assertThat(dealyedQueue.containsAll(Arrays.asList(1, 1))).isTrue();
assertThat(dealyedQueue.containsAll(Arrays.asList(1, 2, 1))).isTrue();
dealyedQueue.destroy();
}

@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test;
import org.redisson.api.RMultimapCache;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@ -34,5 +35,20 @@ public class RedissonListMultimapCacheTest extends RedissonBaseMultimapCacheTest
assertThat(multimap.get("1").retainAll(Arrays.asList("1"))).isTrue();
assertThat(multimap.get("1").removeAll(Arrays.asList("1"))).isTrue();
}
@Test
public void testContainsAll() {
RMultimapCache<String, String> multimap = getMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.put("1", "3");
assertThat(multimap.get("1").containsAll(List.of("1", "2"))).isTrue();
assertThat(multimap.get("1").containsAll(List.of("1", "2", "4"))).isFalse();
assertThat(multimap.get("1").containsAll(List.of("1", "2", "1"))).isTrue();
assertThat(multimap.get("1").containsAll(List.of("1", "1"))).isTrue();
}
}

@ -757,6 +757,26 @@ public class RedissonListTest extends RedisDockerTest {
Assertions.assertEquals(8, index);
}
@Test
public void testSubListContainsAll() {
List<Integer> list = redisson.getList("list");
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(6);
list.add(7);
list.add(8);
list.add(9);
list.add(10);
List<Integer> subList = list.subList(3, 7);
assertThat(subList.containsAll(List.of(4, 5))).isTrue();
assertThat(subList.containsAll(List.of(4, 4))).isTrue();
assertThat(subList.containsAll(List.of(4, 5, 4))).isTrue();
}
@Test
public void testSubListMiddle() {
List<Integer> list = redisson.getList("list");
@ -1160,6 +1180,9 @@ public class RedissonListTest extends RedisDockerTest {
Assertions.assertTrue(list.containsAll(Arrays.asList(30, 11)));
Assertions.assertFalse(list.containsAll(Arrays.asList(30, 711, 11)));
Assertions.assertTrue(list.containsAll(Arrays.asList(30)));
Assertions.assertTrue(list.containsAll(Arrays.asList(30, 30)));
Assertions.assertTrue(list.containsAll(Arrays.asList(30, 11, 30)));
}
@Test

@ -3,6 +3,7 @@ package org.redisson;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.redisson.api.RMultimapCache;
@ -32,5 +33,19 @@ public class RedissonSetMultimapCacheTest extends RedissonBaseMultimapCacheTest
assertThat(multimap.get("1").retainAll(Arrays.asList("1"))).isTrue();
assertThat(multimap.get("1").removeAll(Arrays.asList("1"))).isTrue();
}
@Test
public void testContainsAll() {
RMultimapCache<String, String> multimap = getMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.put("1", "3");
assertThat(multimap.get("1").containsAll(List.of("1", "2"))).isTrue();
assertThat(multimap.get("1").containsAll(List.of("1", "2", "4"))).isFalse();
assertThat(multimap.get("1").containsAll(List.of("1", "2", "1"))).isTrue();
assertThat(multimap.get("1").containsAll(List.of("1", "1"))).isTrue();
}
}

Loading…
Cancel
Save