diff --git a/redisson/src/main/java/org/redisson/RedissonList.java b/redisson/src/main/java/org/redisson/RedissonList.java index 7642b6f6c..bacb287d3 100644 --- a/redisson/src/main/java/org/redisson/RedissonList.java +++ b/redisson/src/main/java/org/redisson/RedissonList.java @@ -330,25 +330,25 @@ public class RedissonList extends RedissonExpirable implements RList { } private RFuture> distributedScanIteratorAsync(String iteratorName, int count) { - List args = new ArrayList<>(1); - args.add(count); - return commandExecutor.evalWriteAsync(getRawName(), codec, EVAL_LIST_SCAN, "local start_index = redis.call('get', KEYS[2]); " - + "if start_index ~= false " - + "then start_index = tonumber(start_index); " - + "else start_index = 0;" + + "if start_index ~= false then " + + "start_index = tonumber(start_index); " + + "else " + + "start_index = 0;" + + "end;" + + "if start_index == -1 then " + + "return {0, {}};" + "end;" - + "if start_index == -1 then return {0, {}}; end;" + "local end_index = start_index + ARGV[1];" + "local result; " + "result = redis.call('lrange', KEYS[1], start_index, end_index - 1); " - + "if end_index > redis.call('llen', KEYS[1]) " - + "then end_index = -1;" + + "if end_index > redis.call('llen', KEYS[1]) then " + + "end_index = -1;" + "end; " + "redis.call('setex', KEYS[2], 3600, end_index);" + "return {end_index, result};", - Arrays.asList(getRawName(), iteratorName), args.toArray()); + Arrays.asList(getRawName(), iteratorName), count); } public RFuture> getAsync(int...indexes) { diff --git a/redisson/src/main/java/org/redisson/RedissonListMultimapValues.java b/redisson/src/main/java/org/redisson/RedissonListMultimapValues.java index 4490dec83..3169a983c 100644 --- a/redisson/src/main/java/org/redisson/RedissonListMultimapValues.java +++ b/redisson/src/main/java/org/redisson/RedissonListMultimapValues.java @@ -393,26 +393,23 @@ public class RedissonListMultimapValues extends RedissonExpirable implements } private RFuture> distributedScanIteratorAsync(String iteratorName, int count) { - List args = new ArrayList<>(2); - args.add(System.currentTimeMillis()); - args.add(count); - return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_SSCAN, - "local start_index = redis.call('get', KEYS[2]); " - + "if start_index ~= false " - + "then start_index = tonumber(start_index); " - + "else start_index = 0;" + "local cursor = redis.call('get', KEYS[3]); " + + "if cursor ~= false then " + + "cursor = tonumber(cursor); " + + "else " + + "cursor = 0;" + + "end;" + + "if start_index == -1 then " + + "return {0, {}}; " + "end;" - + "if start_index == -1 then return {0, {}}; end;" + "local end_index = start_index + ARGV[1];" + "local result; " + "result = redis.call('lrange', KEYS[1], start_index, end_index - 1); " - + "if end_index > redis.call('llen', KEYS[1]) " - + "then end_index = -1;" + + "if end_index > redis.call('llen', KEYS[1]) then " + + "end_index = -1;" + "end; " + "redis.call('setex', KEYS[2], 3600, end_index);" - + "return {end_index, result};" - + "local expireDate = 92233720368547758; " + "local expirations = redis.call('zmscore', KEYS[1], result[2])" + "for i = #expirations, 1, -1 do " @@ -423,8 +420,8 @@ public class RedissonListMultimapValues extends RedissonExpirable implements + "end; " + "end; " + "end; " - + "return result;", - Arrays.asList(timeoutSetName, getRawName(), iteratorName), args.toArray()); + + "return {end_index, result[2]};", + Arrays.asList(timeoutSetName, getRawName(), iteratorName), System.currentTimeMillis(), count); } @Override diff --git a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java index e9e2adeea..8767fd766 100644 --- a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java +++ b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java @@ -573,12 +573,15 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc args.add(count); return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_ZSCAN, - "local cursor = redis.call('get', KEYS[2]); " - + "if cursor ~= false " - + "then cursor = tonumber(cursor); " - + "else cursor = 0;" + "local cursor = redis.call('get', KEYS[3]); " + + "if cursor ~= false then " + + "cursor = tonumber(cursor); " + + "else " + + "cursor = 0;" + + "end;" + + "if start_index == -1 then " + + "return {0, {}}; " + "end;" - + "if cursor == -1 then return {0, {}}; end;" + "local result; " + "if (#ARGV == 2) then " + "result = redis.call('zscan', KEYS[1], cursor, 'match', ARGV[1], 'count', ARGV[2]); " @@ -586,9 +589,10 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc + "result = redis.call('zscan', KEYS[1], cursor, 'count', ARGV[1]); " + "end;" + "local next_cursor = result[1]" - + "if next_cursor ~= \"0\" " - + "then redis.call('setex', KEYS[2], 3600, next_cursor);" - + "else redis.call('setex', KEYS[2], 3600, -1);" + + "if next_cursor ~= \"0\" then " + + "redis.call('setex', KEYS[2], 3600, next_cursor);" + + "else " + + "redis.call('setex', KEYS[2], 3600, -1);" + "end; " + "local res = {};" + "for i, value in ipairs(result[2]) do " diff --git a/redisson/src/main/java/org/redisson/RedissonSet.java b/redisson/src/main/java/org/redisson/RedissonSet.java index 99f233788..9de9c70e1 100644 --- a/redisson/src/main/java/org/redisson/RedissonSet.java +++ b/redisson/src/main/java/org/redisson/RedissonSet.java @@ -153,21 +153,25 @@ public class RedissonSet extends RedissonExpirable implements RSet, ScanIt return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_SSCAN, "local cursor = redis.call('get', KEYS[2]); " - + "if cursor ~= false " - + "then cursor = tonumber(cursor); " - + "else cursor = 0;" + + "if cursor ~= false then " + + "cursor = tonumber(cursor); " + + "else " + + "cursor = 0;" + + "end;" + + "if start_index == -1 then " + + "return {0, {}}; " + "end;" - + "if cursor == -1 then return {0, {}}; end;" + "local result; " + "if (#ARGV == 2) then " - + "result = redis.call('sscan', KEYS[1], cursor, 'match', ARGV[1], 'count', ARGV[2]); " + + "result = redis.call('sscan', KEYS[1], cursor, 'match', ARGV[1], 'count', ARGV[2]); " + "else " - + "result = redis.call('sscan', KEYS[1], cursor, 'count', ARGV[1]); " + + "result = redis.call('sscan', KEYS[1], cursor, 'count', ARGV[1]); " + "end;" + "local next_cursor = result[1]" - + "if next_cursor ~= \"0\" " - + "then redis.call('setex', KEYS[2], 3600, next_cursor);" - + "else redis.call('setex', KEYS[2], 3600, -1);" + + "if next_cursor ~= \"0\" then " + + "redis.call('setex', KEYS[2], 3600, next_cursor);" + + "else " + + "redis.call('setex', KEYS[2], 3600, -1);" + "end; " + "return result;", Arrays.asList(getRawName(), iteratorName), args.toArray()); diff --git a/redisson/src/main/java/org/redisson/RedissonSetMultimapValues.java b/redisson/src/main/java/org/redisson/RedissonSetMultimapValues.java index e6c8799ff..47d7c2381 100644 --- a/redisson/src/main/java/org/redisson/RedissonSetMultimapValues.java +++ b/redisson/src/main/java/org/redisson/RedissonSetMultimapValues.java @@ -273,20 +273,25 @@ public class RedissonSetMultimapValues extends RedissonExpirable implements R return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_SSCAN, "local cursor = redis.call('get', KEYS[3]); " - + "if cursor ~= false " - + "then cursor = tonumber(cursor); " - + "else cursor = 0;" + + "if cursor ~= false then " + + "cursor = tonumber(cursor); " + + "else" + + " cursor = 0;" + + "end;" + + "if start_index == -1 then " + + "return {0, {}}; " + "end;" - + "if cursor == -1 then return {0, {}}; end;" + "local result; " - + "if (#ARGV == 3) " - + "then result = redis.call('sscan', KEYS[2], cursor, 'match', ARGV[2], 'count', ARGV[3]); " - + "else result = redis.call('sscan', KEYS[2], cursor, 'count', ARGV[2]); " + + "if (#ARGV == 3) then " + + "result = redis.call('sscan', KEYS[2], cursor, 'match', ARGV[2], 'count', ARGV[3]); " + + "else" + + "result = redis.call('sscan', KEYS[2], cursor, 'count', ARGV[2]); " + "end;" + "local next_cursor = result[1]" - + "if next_cursor ~= \"0\" " - + "then redis.call('setex', KEYS[3], 3600, next_cursor);" - + "else redis.call('setex', KEYS[3], 3600, -1);" + + "if next_cursor ~= \"0\" then " + + "redis.call('setex', KEYS[3], 3600, next_cursor);" + + "else " + + "redis.call('setex', KEYS[3], 3600, -1);" + "end; " + "local expireDate = 92233720368547758; " diff --git a/redisson/src/main/java/org/redisson/RedissonSortedSet.java b/redisson/src/main/java/org/redisson/RedissonSortedSet.java index 41732fdd3..413c78abd 100644 --- a/redisson/src/main/java/org/redisson/RedissonSortedSet.java +++ b/redisson/src/main/java/org/redisson/RedissonSortedSet.java @@ -419,25 +419,25 @@ public class RedissonSortedSet extends RedissonObject implements RSortedSet> distributedScanIteratorAsync(String iteratorName, int count) { - List args = new ArrayList<>(1); - args.add(count); - return commandExecutor.evalWriteAsync(getRawName(), codec, EVAL_LIST_SCAN, "local start_index = redis.call('get', KEYS[2]); " - + "if start_index ~= false " - + "then start_index = tonumber(start_index); " - + "else start_index = 0;" + + "if start_index ~= false then " + + "start_index = tonumber(start_index); " + + "else " + + "start_index = 0;" + + "end;" + + "if start_index == -1 then " + + "return {0, {}}; " + "end;" - + "if start_index == -1 then return {0, {}}; end;" + "local end_index = start_index + ARGV[1];" + "local result; " + "result = redis.call('lrange', KEYS[1], start_index, end_index - 1); " - + "if end_index > redis.call('llen', KEYS[1]) " - + "then end_index = -1;" + + "if end_index > redis.call('llen', KEYS[1]) then " + + "end_index = -1;" + "end; " + "redis.call('setex', KEYS[2], 3600, end_index);" + "return {end_index, result};", - Arrays.asList(getRawName(), iteratorName), args.toArray()); + Arrays.asList(getRawName(), iteratorName), count); } // TODO optimize: get three values each time instead of single