提交 488e89a7 编写于 作者: T Tom Erik Støwer

Call hget only when needed

Signed-off-by: NTom Erik Støwer <testower@gmail.com>
上级 5b241213
...@@ -392,24 +392,27 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs ...@@ -392,24 +392,27 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
if (containsKey(key)) { if (containsKey(key)) {
Long updateTimeout = getUpdateTimeout(); Long updateTimeout = getUpdateTimeout();
List<Object> res = evalWrite(getRawName(), codec, RedisCommands.EVAL_LIST, List<Object> res = evalWrite(getRawName(), codec, RedisCommands.EVAL_LIST,
"local value = redis.call('hget', KEYS[1], ARGV[4]);" "if ARGV[2] == '0' then "
+"if ARGV[2] == '0' then "
+ "redis.call('hdel', KEYS[1], ARGV[4]); " + "redis.call('hdel', KEYS[1], ARGV[4]); "
+ "redis.call('zrem', KEYS[2], ARGV[4]); " + "redis.call('zrem', KEYS[2], ARGV[4]); "
+ "local value = redis.call('hget', KEYS[1], ARGV[4]);"
+ "local msg = struct.pack('Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); " + "local msg = struct.pack('Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); "
+ "redis.call('publish', KEYS[4], msg); " + "redis.call('publish', KEYS[4], msg); "
+ "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[6]); " + "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[6]); "
+ "local syncs = redis.call('publish', KEYS[7], syncMsg); " + "local syncs = redis.call('publish', KEYS[7], syncMsg); "
+ "return {0, syncs};" + "return {0, syncs};"
+ "elseif ARGV[2] ~= '-1' then " + "elseif ARGV[2] ~= '-1' then "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[4]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1, ARGV[6]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1, ARGV[6]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[4]);"
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value), ARGV[6]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value), ARGV[6]); "
+ "end; " + "end; "
...@@ -417,13 +420,15 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs ...@@ -417,13 +420,15 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
+ "local syncs = redis.call('publish', KEYS[8], syncMsg); " + "local syncs = redis.call('publish', KEYS[8], syncMsg); "
+ "return {1, syncs};" + "return {1, syncs};"
+ "else " + "else "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1, ARGV[6]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1, ARGV[6]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[4]);"
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value), ARGV[6]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value), ARGV[6]); "
+ "end; " + "end; "
...@@ -500,23 +505,26 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs ...@@ -500,23 +505,26 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
"exists = false;" + "exists = false;" +
"end;" + "end;" +
"if exists then " "if exists then "
+ "local value = redis.call('hget', KEYS[1], ARGV[i]);"
+ "if ARGV[2] == '0' then " + "if ARGV[2] == '0' then "
+ "redis.call('hdel', KEYS[1], ARGV[i]); " + "redis.call('hdel', KEYS[1], ARGV[i]); "
+ "redis.call('zrem', KEYS[2], ARGV[i]); " + "redis.call('zrem', KEYS[2], ARGV[i]); "
+ "local value = redis.call('hget', KEYS[1], ARGV[i]);"
+ "local msg = struct.pack('Lc0Lc0', string.len(ARGV[i]), ARGV[i], string.len(tostring(value)), tostring(value)); " + "local msg = struct.pack('Lc0Lc0', string.len(ARGV[i]), ARGV[i], string.len(tostring(value)), tostring(value)); "
+ "redis.call('publish', KEYS[4], msg); " + "redis.call('publish', KEYS[4], msg); "
+ "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[i]), ARGV[i], string.len(tostring(value)), tostring(value), ARGV[4]); " + "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[i]), ARGV[i], string.len(tostring(value)), tostring(value), ARGV[4]); "
+ "syncs = syncs + redis.call('publish', KEYS[7], syncMsg); " + "syncs = syncs + redis.call('publish', KEYS[7], syncMsg); "
+ "elseif ARGV[2] ~= '-1' then " + "elseif ARGV[2] ~= '-1' then "
+ "redis.call('hset', KEYS[1], ARGV[i], ARGV[i+1]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[i]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[i], ARGV[i+1]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[i]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], -1, ARGV[4]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], -1, ARGV[4]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[i]);"
+ "redis.call('hset', KEYS[1], ARGV[i], ARGV[i+1]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[i]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], string.len(tostring(value)), tostring(value), ARGV[4]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], string.len(tostring(value)), tostring(value), ARGV[4]); "
+ "end; " + "end; "
...@@ -524,13 +532,15 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs ...@@ -524,13 +532,15 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
+ "syncs = syncs + redis.call('publish', KEYS[8], syncMsg); " + "syncs = syncs + redis.call('publish', KEYS[8], syncMsg); "
+ "added = added + 1;" + "added = added + 1;"
+ "else " + "else "
+ "redis.call('hset', KEYS[1], ARGV[i], ARGV[i+1]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[i], ARGV[i+1]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], -1, ARGV[4]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], -1, ARGV[4]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[i]);"
+ "redis.call('hset', KEYS[1], ARGV[i], ARGV[i+1]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], string.len(tostring(value)), tostring(value), ARGV[4]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[i]), ARGV[i], string.len(ARGV[i+1]), ARGV[i+1], string.len(tostring(value)), tostring(value), ARGV[4]); "
+ "end; " + "end; "
...@@ -627,24 +637,27 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs ...@@ -627,24 +637,27 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
"exists = false;" + "exists = false;" +
"end;" + "end;" +
"if exists then " "if exists then "
+ "local value = redis.call('hget', KEYS[1], ARGV[4]);"
+ "if ARGV[2] == '0' then " + "if ARGV[2] == '0' then "
+ "redis.call('hdel', KEYS[1], ARGV[4]); " + "redis.call('hdel', KEYS[1], ARGV[4]); "
+ "redis.call('zrem', KEYS[2], ARGV[4]); " + "redis.call('zrem', KEYS[2], ARGV[4]); "
+ "local value = redis.call('hget', KEYS[1], ARGV[4]);"
+ "local msg = struct.pack('Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); " + "local msg = struct.pack('Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); "
+ "redis.call('publish', KEYS[4], msg); " + "redis.call('publish', KEYS[4], msg); "
+ "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[6]); " + "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[6]); "
+ "local syncs = redis.call('publish', KEYS[7], syncMsg); " + "local syncs = redis.call('publish', KEYS[7], syncMsg); "
+ "return {0, syncs};" + "return {0, syncs};"
+ "elseif ARGV[2] ~= '-1' then " + "elseif ARGV[2] ~= '-1' then "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[4]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1, ARGV[6]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1, ARGV[6]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[4]);"
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value), ARGV[6]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value), ARGV[6]); "
+ "end; " + "end; "
...@@ -652,13 +665,15 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs ...@@ -652,13 +665,15 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
+ "local syncs = redis.call('publish', KEYS[8], syncMsg); " + "local syncs = redis.call('publish', KEYS[8], syncMsg); "
+ "return {1, syncs};" + "return {1, syncs};"
+ "else " + "else "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[9])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1, ARGV[6]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], -1, ARGV[6]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[4]);"
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[5]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value), ARGV[6]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[5]), ARGV[5], string.len(tostring(value)), tostring(value), ARGV[6]); "
+ "end; " + "end; "
...@@ -2282,29 +2297,32 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs ...@@ -2282,29 +2297,32 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
Long updateTimeout = getUpdateTimeout(); Long updateTimeout = getUpdateTimeout();
double syncId = ThreadLocalRandom.current().nextDouble(); double syncId = ThreadLocalRandom.current().nextDouble();
Long syncs = evalWrite(getRawName(), codec, RedisCommands.EVAL_LONG, Long syncs = evalWrite(getRawName(), codec, RedisCommands.EVAL_LONG,
"local value = redis.call('hget', KEYS[1], ARGV[4]); " "if ARGV[2] == '0' then "
+ "if ARGV[2] == '0' then "
+ "redis.call('hdel', KEYS[1], ARGV[4]); " + "redis.call('hdel', KEYS[1], ARGV[4]); "
+ "redis.call('zrem', KEYS[2], ARGV[4]); " + "redis.call('zrem', KEYS[2], ARGV[4]); "
+ "local value = redis.call('hget', KEYS[1], ARGV[4]); "
+ "local msg = struct.pack('Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); " + "local msg = struct.pack('Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); "
+ "redis.call('publish', KEYS[3], msg); " + "redis.call('publish', KEYS[3], msg); "
+ "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[7]); " + "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[7]); "
+ "return redis.call('publish', KEYS[5], syncMsg); " + "return redis.call('publish', KEYS[5], syncMsg); "
+ "elseif ARGV[2] ~= '-1' then " + "elseif ARGV[2] ~= '-1' then "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[6]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[4]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[6]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6], -1, ARGV[7]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6], -1, ARGV[7]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[4]); "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[6]); "
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6], string.len(tostring(value)), tostring(value), ARGV[7]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6], string.len(tostring(value)), tostring(value), ARGV[7]); "
+ "end; " + "end; "
+ "redis.call('publish', KEYS[4], msg); " + "redis.call('publish', KEYS[4], msg); "
+ "return redis.call('publish', KEYS[6], syncMsg); " + "return redis.call('publish', KEYS[6], syncMsg); "
+ "else " + "else "
+ "redis.call('hset', KEYS[1], ARGV[4], ARGV[6]); " + "redis.call('hset', KEYS[1], ARGV[4], ARGV[6]); "
+ "local msg = struct.pack('Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6]); " + "local msg = struct.pack('Lc0Lc0', string.len(ARGV[4]), ARGV[4], string.len(ARGV[6]), ARGV[6]); "
+ "redis.call('publish', KEYS[4], msg); " + "redis.call('publish', KEYS[4], msg); "
...@@ -2497,36 +2515,41 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs ...@@ -2497,36 +2515,41 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
double syncId = ThreadLocalRandom.current().nextDouble(); double syncId = ThreadLocalRandom.current().nextDouble();
Long updateTimeout = getUpdateTimeout(); Long updateTimeout = getUpdateTimeout();
Long syncs = evalWrite(getRawName(), codec, RedisCommands.EVAL_LONG, Long syncs = evalWrite(getRawName(), codec, RedisCommands.EVAL_LONG,
"local value = redis.call('hget', KEYS[1], ARGV[3]); " "if ARGV[1] == '0' then "
+ "if ARGV[1] == '0' then "
+ "redis.call('hdel', KEYS[1], ARGV[3]); " + "redis.call('hdel', KEYS[1], ARGV[3]); "
+ "redis.call('zrem', KEYS[2], ARGV[3]); " + "redis.call('zrem', KEYS[2], ARGV[3]); "
+ "local value = redis.call('hget', KEYS[1], ARGV[3]); "
+ "local msg = struct.pack('Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(tostring(value)), tostring(value)); " + "local msg = struct.pack('Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(tostring(value)), tostring(value)); "
+ "redis.call('publish', KEYS[3], msg); " + "redis.call('publish', KEYS[3], msg); "
+ "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(tostring(value)), tostring(value), ARGV[5]); " + "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(tostring(value)), tostring(value), ARGV[5]); "
+ "return redis.call('publish', KEYS[5], syncMsg); " + "return redis.call('publish', KEYS[5], syncMsg); "
+ "elseif ARGV[1] ~= '-1' then " + "elseif ARGV[1] ~= '-1' then "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "redis.call('zadd', KEYS[2], ARGV[1], ARGV[3]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "redis.call('zadd', KEYS[2], ARGV[1], ARGV[3]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1, ARGV[5]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1, ARGV[5]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[3]); "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "redis.call('zadd', KEYS[2], ARGV[1], ARGV[3]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[5]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[5]); "
+ "end; " + "end; "
+ "redis.call('publish', KEYS[4], msg); " + "redis.call('publish', KEYS[4], msg); "
+ "return redis.call('publish', KEYS[6], syncMsg); " + "return redis.call('publish', KEYS[6], syncMsg); "
+ "else " + "else "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1, ARGV[5]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1, ARGV[5]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[3]); "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[5]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[5]); "
+ "end; " + "end; "
...@@ -2660,36 +2683,41 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs ...@@ -2660,36 +2683,41 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
Long updateTimeout = getUpdateTimeout(); Long updateTimeout = getUpdateTimeout();
double syncId = ThreadLocalRandom.current().nextDouble(); double syncId = ThreadLocalRandom.current().nextDouble();
Long syncs = evalWrite(getRawName(), codec, RedisCommands.EVAL_LONG, Long syncs = evalWrite(getRawName(), codec, RedisCommands.EVAL_LONG,
"local value = redis.call('hget', KEYS[1], ARGV[3]); " "if ARGV[1] == '0' then "
+ "if ARGV[1] == '0' then "
+ "redis.call('hdel', KEYS[1], ARGV[3]); " + "redis.call('hdel', KEYS[1], ARGV[3]); "
+ "redis.call('zrem', KEYS[2], ARGV[3]); " + "redis.call('zrem', KEYS[2], ARGV[3]); "
+ "local value = redis.call('hget', KEYS[1], ARGV[3]); "
+ "local msg = struct.pack('Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(tostring(value)), tostring(value)); " + "local msg = struct.pack('Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(tostring(value)), tostring(value)); "
+ "redis.call('publish', KEYS[3], msg); " + "redis.call('publish', KEYS[3], msg); "
+ "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(tostring(value)), tostring(value), ARGV[5]); " + "local syncMsg = struct.pack('Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(tostring(value)), tostring(value), ARGV[5]); "
+ "return redis.call('publish', KEYS[5], msg); " + "return redis.call('publish', KEYS[5], msg); "
+ "elseif ARGV[1] ~= '-1' then " + "elseif ARGV[1] ~= '-1' then "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "redis.call('zadd', KEYS[2], ARGV[1], ARGV[3]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "redis.call('zadd', KEYS[2], ARGV[1], ARGV[3]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1, ARGV[5]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1, ARGV[5]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[3]); "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "redis.call('zadd', KEYS[2], ARGV[1], ARGV[3]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[5]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[5]); "
+ "end; " + "end; "
+ "redis.call('publish', KEYS[4], msg); " + "redis.call('publish', KEYS[4], msg); "
+ "return redis.call('publish', KEYS[6], syncMsg); " + "return redis.call('publish', KEYS[6], syncMsg); "
+ "else " + "else "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); " + "local oldValueRequired = tonumber(redis.call('get', KEYS[7])); "
+ "local msg, syncMsg; " + "local msg, syncMsg; "
+ "if oldValueRequired == nil or oldValueRequired < 1 then " + "if oldValueRequired == nil or oldValueRequired < 1 then "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0h', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1); " + "msg = struct.pack('Lc0Lc0h', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1); "
+ "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1, ARGV[5]); " + "syncMsg = struct.pack('Lc0Lc0hd', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], -1, ARGV[5]); "
+ "else " + "else "
+ "local value = redis.call('hget', KEYS[1], ARGV[3]); "
+ "redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); "
+ "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); " + "msg = struct.pack('Lc0Lc0Lc0', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value)); "
+ "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[5]); " + "syncMsg = struct.pack('Lc0Lc0Lc0d', string.len(ARGV[3]), ARGV[3], string.len(ARGV[4]), ARGV[4], string.len(tostring(value)), tostring(value), ARGV[5]); "
+ "end; " + "end; "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册