From 26a03b55de17a9243e9cfc75a65ad7eccb872076 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Wed, 17 Jun 2020 22:11:37 -0400 Subject: [PATCH] Un-reinvent the clustered script execution wheel. --- .../textsecuregcm/redis/ClusterLuaScript.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/redis/ClusterLuaScript.java b/service/src/main/java/org/whispersystems/textsecuregcm/redis/ClusterLuaScript.java index c1f0981c6..494288d3b 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/redis/ClusterLuaScript.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/redis/ClusterLuaScript.java @@ -46,20 +46,12 @@ public class ClusterLuaScript { public Object execute(final List keys, final List args) { return redisCluster.withWriteCluster(connection -> { final RedisAdvancedClusterCommands clusterCommands = connection.sync(); - final RedisCommands redisCommands; - - if (keys.isEmpty()) { - redisCommands = clusterCommands.masters().commands(0); - } else { - final int slot = SlotHash.getSlot(keys.get(0)); - redisCommands = clusterCommands.nodes(node -> node.is(RedisClusterNode.NodeFlag.MASTER) && node.hasSlot(slot)).commands(0); - } try { - return redisCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY)); + return clusterCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY)); } catch (final RedisNoScriptException e) { clusterCommands.scriptLoad(script); - return redisCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY)); + return clusterCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY)); } }); }