mirror of
https://github.com/signalapp/Signal-Server
synced 2026-02-28 06:43:18 +00:00
Add binary execution methods to ClusterLuaScript.
This commit is contained in:
committed by
Jon Chambers
parent
69c8968cb0
commit
3d3790fdbc
@@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
public class ClusterLuaScript {
|
||||
@@ -22,7 +23,8 @@ public class ClusterLuaScript {
|
||||
private final String script;
|
||||
private final String sha;
|
||||
|
||||
private static final String[] STRING_ARRAY = new String[0];
|
||||
private static final String[] STRING_ARRAY = new String[0];
|
||||
private static final byte[][] BYTE_ARRAY_ARRAY = new byte[0][];
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ClusterLuaScript.class);
|
||||
|
||||
@@ -66,4 +68,22 @@ public class ClusterLuaScript {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Object executeBinary(final List<byte[]> keys, final List<byte[]> args) {
|
||||
return redisCluster.withBinaryWriteCluster(connection -> {
|
||||
try {
|
||||
final RedisAdvancedClusterCommands<byte[], byte[]> binaryCommands = connection.sync();
|
||||
|
||||
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));
|
||||
return binaryCommands.evalsha(sha, scriptOutputType, keys.toArray(BYTE_ARRAY_ARRAY), args.toArray(BYTE_ARRAY_ARRAY));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log.warn("Failed to execute script", e);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user