Fixed according to comments

Signed-off-by: Danila Varatyntsev <danila.varatyntsev@xa.epicgames.com>
pull/3970/head
Danila Varatyntsev 3 years ago
parent e775db2c72
commit e24d75a613

@ -330,25 +330,25 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
}
private RFuture<ScanResult<Object>> distributedScanIteratorAsync(String iteratorName, int count) {
List<Object> 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.<Object>asList(getRawName(), iteratorName), args.toArray());
Arrays.<Object>asList(getRawName(), iteratorName), count);
}
public RFuture<List<V>> getAsync(int...indexes) {

@ -393,26 +393,23 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
}
private RFuture<ScanResult<Object>> distributedScanIteratorAsync(String iteratorName, int count) {
List<Object> 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<V> extends RedissonExpirable implements
+ "end; "
+ "end; "
+ "end; "
+ "return result;",
Arrays.<Object>asList(timeoutSetName, getRawName(), iteratorName), args.toArray());
+ "return {end_index, result[2]};",
Arrays.<Object>asList(timeoutSetName, getRawName(), iteratorName), System.currentTimeMillis(), count);
}
@Override

@ -573,12 +573,15 @@ public class RedissonScoredSortedSet<V> 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<V> 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 "

@ -153,21 +153,25 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V>, 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.<Object>asList(getRawName(), iteratorName), args.toArray());

@ -273,20 +273,25 @@ public class RedissonSetMultimapValues<V> 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; "

@ -419,25 +419,25 @@ public class RedissonSortedSet<V> extends RedissonObject implements RSortedSet<V
}
private RFuture<ScanResult<Object>> distributedScanIteratorAsync(String iteratorName, int count) {
List<Object> 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.<Object>asList(getRawName(), iteratorName), args.toArray());
Arrays.<Object>asList(getRawName(), iteratorName), count);
}
// TODO optimize: get three values each time instead of single

Loading…
Cancel
Save