Reload scripts across the whole cluster if one shard is missing the script.

This commit is contained in:
Jon Chambers
2021-01-10 14:43:58 -05:00
committed by Jon Chambers
parent 2d697ac8db
commit 1b53f10091
2 changed files with 22 additions and 32 deletions

View File

@@ -64,7 +64,7 @@ public class ClusterLuaScript {
try {
return clusterCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY));
} catch (final RedisNoScriptException e) {
clusterCommands.scriptLoad(script);
reloadScript();
return clusterCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY));
}
} catch (final Exception e) {
@@ -82,7 +82,7 @@ public class ClusterLuaScript {
try {
return binaryCommands.evalsha(sha, scriptOutputType, keys.toArray(BYTE_ARRAY_ARRAY), args.toArray(BYTE_ARRAY_ARRAY));
} catch (final RedisNoScriptException e) {
binaryCommands.scriptLoad(script.getBytes(StandardCharsets.UTF_8));
reloadScript();
return binaryCommands.evalsha(sha, scriptOutputType, keys.toArray(BYTE_ARRAY_ARRAY), args.toArray(BYTE_ARRAY_ARRAY));
}
} catch (final Exception e) {
@@ -91,4 +91,8 @@ public class ClusterLuaScript {
}
});
}
private void reloadScript() {
redisCluster.useCluster(connection -> connection.sync().upstream().commands().scriptLoad(script));
}
}