LUA arrays start index fixed

pull/469/head
Nikita 9 years ago
parent 9bd6a0387b
commit 89312c230f

@ -143,13 +143,13 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN_WITH_VALUES,
"local items = redis.call('lrange', KEYS[1], 0, -1) " +
"for i=1, #items do " +
"for j = 0, table.getn(ARGV), 1 do " +
"for j = 1, #ARGV, 1 do " +
"if items[i] == ARGV[j] then " +
"table.remove(ARGV, j) " +
"end " +
"end " +
"end " +
"return table.getn(ARGV) == 0 and 1 or 0",
"return #ARGV == 0 and 1 or 0",
Collections.<Object>singletonList(getName()), c.toArray());
}
@ -222,7 +222,7 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
public Future<Boolean> removeAllAsync(Collection<?> c) {
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN_WITH_VALUES,
"local v = 0 " +
"for i = 0, table.getn(ARGV), 1 do "
"for i = 1, #ARGV, 1 do "
+ "if redis.call('lrem', KEYS[1], 0, ARGV[i]) == 1 "
+ "then v = 1 end "
+"end "
@ -246,11 +246,10 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
"local changed = 0 " +
"local items = redis.call('lrange', KEYS[1], 0, -1) "
+ "local i = 1 "
+ "local s = table.getn(items) "
+ "while i <= s do "
+ "while i <= #items do "
+ "local element = items[i] "
+ "local isInAgrs = false "
+ "for j = 0, table.getn(ARGV), 1 do "
+ "for j = 1, #ARGV, 1 do "
+ "if ARGV[j] == element then "
+ "isInAgrs = true "
+ "break "
@ -390,7 +389,7 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
"local key = KEYS[1] " +
"local obj = ARGV[1] " +
"local items = redis.call('lrange', key, 0, -1) " +
"for i = #items, 0, -1 do " +
"for i = #items, 1, -1 do " +
"if items[i] == obj then " +
"return i - 1 " +
"end " +

@ -199,13 +199,13 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
+ "return 0;"
+ "end; " +
"local items = redis.call('lrange', KEYS[2], 0, -1);" +
"for i = 0, #items, 1 do " +
"for j = 2, table.getn(ARGV), 1 do "
"for i = 1, #items, 1 do " +
"for j = 2, #ARGV, 1 do "
+ "if ARGV[j] == items[i] "
+ "then table.remove(ARGV, j) end "
+ "end; "
+ "end;"
+ "return table.getn(ARGV) == 2 and 1 or 0; ",
+ "return #ARGV == 2 and 1 or 0; ",
Arrays.<Object>asList(timeoutSetName, getName()), args.toArray());
}
@ -340,7 +340,7 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
"local changed = 0; " +
"local s = redis.call('lrange', KEYS[2], 0, -1); "
+ "local i = 0; "
+ "local i = 1; "
+ "while i <= #s do "
+ "local element = s[i]; "
+ "local isInAgrs = false; "
@ -508,7 +508,7 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
+ "end; " +
"local items = redis.call('lrange', KEYS[1], 0, -1) " +
"for i = #items, 0, -1 do " +
"for i = #items, 1, -1 do " +
"if items[i] == ARGV[1] then " +
"return i - 1 " +
"end " +

@ -107,7 +107,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
public Future<Boolean> containsValueAsync(Object value) {
return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 4),
"local s = redis.call('hvals', KEYS[1]);" +
"for i = 0, table.getn(s), 1 do "
"for i = 1, #s, 1 do "
+ "if ARGV[1] == s[i] then "
+ "return 1 "
+ "end "

@ -280,13 +280,13 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
public Future<Boolean> containsAllAsync(Collection<?> c) {
return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN_WITH_VALUES,
"local s = redis.call('zrange', KEYS[1], 0, -1);" +
"for i = 0, table.getn(s), 1 do " +
"for j = 0, table.getn(ARGV), 1 do "
"for i = 1, #s, 1 do " +
"for j = 1, #ARGV, 1 do "
+ "if ARGV[j] == s[i] "
+ "then table.remove(ARGV, j) end "
+ "end; "
+ "end;"
+ "return table.getn(ARGV) == 0 and 1 or 0; ",
+ "return #ARGV == 0 and 1 or 0; ",
Collections.<Object>singletonList(getName()), c.toArray());
}
@ -316,11 +316,11 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN_WITH_VALUES,
"local changed = 0 " +
"local s = redis.call('zrange', KEYS[1], 0, -1) "
+ "local i = 0 "
+ "while i <= table.getn(s) do "
+ "local i = 1 "
+ "while i <= #s do "
+ "local element = s[i] "
+ "local isInAgrs = false "
+ "for j = 0, table.getn(ARGV), 1 do "
+ "for j = 1, #ARGV, 1 do "
+ "if ARGV[j] == element then "
+ "isInAgrs = true "
+ "break "

@ -22,7 +22,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import org.redisson.client.codec.Codec;
@ -168,13 +167,13 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V> {
public Future<Boolean> containsAllAsync(Collection<?> c) {
return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN_WITH_VALUES,
"local s = redis.call('smembers', KEYS[1]);" +
"for i = 0, table.getn(s), 1 do " +
"for j = 0, table.getn(ARGV), 1 do "
"for i = 1, #s, 1 do " +
"for j = 1, #ARGV, 1 do "
+ "if ARGV[j] == s[i] "
+ "then table.remove(ARGV, j) end "
+ "end; "
+ "end;"
+ "return table.getn(ARGV) == 0 and 1 or 0; ",
+ "return #ARGV == 0 and 1 or 0; ",
Collections.<Object>singletonList(getName()), c.toArray());
}
@ -205,11 +204,11 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V> {
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN_WITH_VALUES,
"local changed = 0 " +
"local s = redis.call('smembers', KEYS[1]) "
+ "local i = 0 "
+ "while i <= table.getn(s) do "
+ "local i = 1 "
+ "while i <= #s do "
+ "local element = s[i] "
+ "local isInAgrs = false "
+ "for j = 0, table.getn(ARGV), 1 do "
+ "for j = 1, #ARGV, 1 do "
+ "if ARGV[j] == element then "
+ "isInAgrs = true "
+ "break "
@ -229,7 +228,7 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V> {
public Future<Boolean> removeAllAsync(Collection<?> c) {
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN_WITH_VALUES,
"local v = 0 " +
"for i = 0, table.getn(ARGV), 1 do "
"for i = 1, #ARGV, 1 do "
+ "if redis.call('srem', KEYS[1], ARGV[i]) == 1 "
+ "then v = 1 end "
+"end "

@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -336,14 +335,14 @@ public class RedissonSetCache<V> extends RedissonExpirable implements RSetCache<
public Future<Boolean> containsAllAsync(Collection<?> c) {
return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN_WITH_VALUES,
"local s = redis.call('hvals', KEYS[1]);" +
"for i = 0, table.getn(s), 1 do " +
"for j = 0, table.getn(ARGV), 1 do "
"for i = 1, #s, 1 do " +
"for j = 1, #ARGV, 1 do "
+ "if ARGV[j] == s[i] then "
+ "table.remove(ARGV, j) "
+ "end "
+ "end; "
+ "end;"
+ "return table.getn(ARGV) == 0 and 1 or 0; ",
+ "return #ARGV == 0 and 1 or 0; ",
Collections.<Object>singletonList(getName()), c.toArray());
}

@ -251,13 +251,13 @@ public class RedissonSetMultimapValues<V> extends RedissonExpirable implements R
+ "return 0;"
+ "end; " +
"local s = redis.call('smembers', KEYS[2]);" +
"for i = 0, table.getn(s), 1 do " +
"for j = 2, table.getn(ARGV), 1 do "
"for i = 1, #s, 1 do " +
"for j = 2, #ARGV, 1 do "
+ "if ARGV[j] == s[i] "
+ "then table.remove(ARGV, j) end "
+ "end; "
+ "end;"
+ "return table.getn(ARGV) == 2 and 1 or 0; ",
+ "return #ARGV == 2 and 1 or 0; ",
Arrays.<Object>asList(timeoutSetName, getName()), args.toArray());
}
@ -307,11 +307,11 @@ public class RedissonSetMultimapValues<V> extends RedissonExpirable implements R
"local changed = 0 " +
"local s = redis.call('smembers', KEYS[2]) "
+ "local i = 0 "
+ "while i <= table.getn(s) do "
+ "local i = 1 "
+ "while i <= #s do "
+ "local element = s[i] "
+ "local isInAgrs = false "
+ "for j = 2, table.getn(ARGV), 1 do "
+ "for j = 2, #ARGV, 1 do "
+ "if ARGV[j] == element then "
+ "isInAgrs = true "
+ "break "
@ -350,7 +350,7 @@ public class RedissonSetMultimapValues<V> extends RedissonExpirable implements R
+ "end; " +
"local v = 0 " +
"for i = 2, table.getn(ARGV), 1 do "
"for i = 2, #ARGV, 1 do "
+ "if redis.call('srem', KEYS[2], ARGV[i]) == 1 "
+ "then v = 1 end "
+"end "

@ -104,13 +104,13 @@ public class RedissonSubList<V> extends RedissonList<V> implements RList<V> {
"local toIndex = table.remove(ARGV, 2);" +
"local items = redis.call('lrange', KEYS[1], tonumber(fromIndex), tonumber(toIndex)) " +
"for i=1, #items do " +
"for j = 0, #ARGV, 1 do " +
"for j = 1, #ARGV, 1 do " +
"if items[i] == ARGV[j] then " +
"table.remove(ARGV, j) " +
"end " +
"end " +
"end " +
"return table.getn(ARGV) == 0 and 1 or 0",
"return #ARGV == 0 and 1 or 0",
Collections.<Object>singletonList(getName()), params.toArray());
}
@ -203,11 +203,10 @@ public class RedissonSubList<V> extends RedissonList<V> implements RList<V> {
"local toIndex = table.remove(ARGV, 2);" +
"local items = redis.call('lrange', KEYS[1], fromIndex, toIndex) "
+ "local i = 1 "
+ "local s = table.getn(items) "
+ "while i <= s do "
+ "while i <= #items do "
+ "local element = items[i] "
+ "local isInAgrs = false "
+ "for j = 0, table.getn(ARGV), 1 do "
+ "for j = 1, #ARGV, 1 do "
+ "if ARGV[j] == element then "
+ "isInAgrs = true "
+ "break "

Loading…
Cancel
Save