From 3c187342808345c6bbc3922eaf93614bc77bd4b3 Mon Sep 17 00:00:00 2001 From: Avital Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Sun, 10 Apr 2022 12:48:09 +0300 Subject: [PATCH] Update FUNCTION LOAD changes (from release 7.0 rc3) (#2973) * Update FUNCTION LOAD changes (Release 7.0 rc3) * update FUNCTION LIST * remove function load params * fix failure * lgtm report fix --- .../redis/clients/jedis/CommandObjects.java | 20 ++++----- src/main/java/redis/clients/jedis/Jedis.java | 16 ++++---- .../clients/jedis/MultiNodePipelineBase.java | 16 ++++---- .../java/redis/clients/jedis/Pipeline.java | 16 ++++---- .../redis/clients/jedis/TransactionBase.java | 16 ++++---- .../redis/clients/jedis/UnifiedJedis.java | 16 ++++---- .../commands/FunctionBinaryCommands.java | 22 +++++----- .../jedis/commands/FunctionCommands.java | 22 +++++----- .../FunctionPipelineBinaryCommands.java | 5 +-- .../commands/FunctionPipelineCommands.java | 5 +-- .../jedis/params/FunctionLoadParams.java | 41 ------------------- .../clients/jedis/resps/LibraryInfo.java | 23 ++++------- .../commands/jedis/ScriptingCommandsTest.java | 41 ++++++++++--------- 13 files changed, 101 insertions(+), 158 deletions(-) delete mode 100644 src/main/java/redis/clients/jedis/params/FunctionLoadParams.java diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 483704d630..e036592129 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -2821,14 +2821,12 @@ public final CommandObject> functionListWithCode(String librar .add(libraryNamePattern).add(WITHCODE), BuilderFactory.LIBRARY_LIST); } - public final CommandObject functionLoad(String engineName, String libraryName, String functionCode) { - return new CommandObject<>(commandArguments(FUNCTION).add(LOAD).add(engineName) - .add(libraryName).add(functionCode), BuilderFactory.STRING); + public final CommandObject functionLoad(String functionCode) { + return new CommandObject<>(commandArguments(FUNCTION).add(LOAD).add(functionCode), BuilderFactory.STRING); } - public final CommandObject functionLoad(String engineName, String libraryName, FunctionLoadParams params, String functionCode) { - return new CommandObject<>(commandArguments(FUNCTION).add(LOAD).add(engineName) - .add(libraryName).addParams(params).add(functionCode), BuilderFactory.STRING); + public final CommandObject functionLoadReplace(String functionCode) { + return new CommandObject<>(commandArguments(FUNCTION).add(LOAD).add(REPLACE).add(functionCode), BuilderFactory.STRING); } public final CommandObject functionStats() { @@ -2893,14 +2891,12 @@ public final CommandObject> functionListWithCode(byte[] libraryName add(libraryNamePattern).add(WITHCODE), BuilderFactory.RAW_OBJECT_LIST); } - public final CommandObject functionLoad(byte[] engineName, byte[] libraryName, byte[] functionCode) { - return new CommandObject<>(commandArguments(FUNCTION).add(LOAD).add(engineName) - .add(libraryName).add(functionCode), BuilderFactory.STRING); + public final CommandObject functionLoad(byte[] functionCode) { + return new CommandObject<>(commandArguments(FUNCTION).add(LOAD).add(functionCode), BuilderFactory.STRING); } - public final CommandObject functionLoad(byte[] engineName, byte[] libraryName, FunctionLoadParams params, byte[] functionCode) { - return new CommandObject<>(commandArguments(FUNCTION).add(LOAD).add(engineName) - .add(libraryName).addParams(params).add(functionCode), BuilderFactory.STRING); + public final CommandObject functionLoadReplace(byte[] functionCode) { + return new CommandObject<>(commandArguments(FUNCTION).add(LOAD).add(REPLACE).add(functionCode), BuilderFactory.STRING); } public final CommandObject functionRestore(byte[] serializedValue) { diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 406e0bf8d3..09cb0713f4 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8843,15 +8843,15 @@ public String functionDelete(final String libraryName) { } @Override - public String functionLoad(final String engineName, final String libraryName, final String functionCode) { + public String functionLoad(final String functionCode) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + return connection.executeCommand(commandObjects.functionLoad(functionCode)); } @Override - public String functionLoad(final String engineName, final String libraryName, final FunctionLoadParams params, final String functionCode) { + public String functionLoadReplace(final String functionCode) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + return connection.executeCommand(commandObjects.functionLoadReplace(functionCode)); } @Override @@ -9447,15 +9447,15 @@ public List functionListWithCode(final byte[] libraryNamePattern) { } @Override - public String functionLoad(final byte[] engineName, final byte[] libraryName, final byte[] functionCode) { + public String functionLoad(final byte[] functionCode) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + return connection.executeCommand(commandObjects.functionLoad(functionCode)); } @Override - public String functionLoad(final byte[] engineName, final byte[] libraryName, final FunctionLoadParams params, final byte[] functionCode) { + public String functionLoadReplace(final byte[] functionCode) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + return connection.executeCommand(commandObjects.functionLoadReplace(functionCode)); } @Override diff --git a/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java b/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java index 12d8f9f862..7883d3a1b5 100644 --- a/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java +++ b/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java @@ -1734,23 +1734,23 @@ public Response> functionListWithCode(final byte[] libraryNamePatte } @Override - public Response functionLoad(byte[] engineName, byte[] libraryName, byte[] functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + public Response functionLoad(byte[] functionCode) { + return appendCommand(commandObjects.functionLoad(functionCode)); } @Override - public Response functionLoad(String engineName, String libraryName, String functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + public Response functionLoad(String functionCode) { + return appendCommand(commandObjects.functionLoad(functionCode)); } @Override - public Response functionLoad(byte[] engineName, byte[] libraryName, FunctionLoadParams params, byte[] functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + public Response functionLoadReplace(byte[] functionCode) { + return appendCommand(commandObjects.functionLoadReplace(functionCode)); } @Override - public Response functionLoad(String engineName, String libraryName, FunctionLoadParams params, String functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + public Response functionLoadReplace(String functionCode) { + return appendCommand(commandObjects.functionLoadReplace(functionCode)); } @Override diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 21614525bc..4fc0b3f0d4 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -1736,23 +1736,23 @@ public Response> functionListWithCode(final byte[] libraryNamePatte } @Override - public Response functionLoad(byte[] engineName, byte[] libraryName, byte[] functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + public Response functionLoad(byte[] functionCode) { + return appendCommand(commandObjects.functionLoad(functionCode)); } @Override - public Response functionLoad(String engineName, String libraryName, String functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + public Response functionLoad(String functionCode) { + return appendCommand(commandObjects.functionLoad(functionCode)); } @Override - public Response functionLoad(byte[] engineName, byte[] libraryName, FunctionLoadParams params, byte[] functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + public Response functionLoadReplace(byte[] functionCode) { + return appendCommand(commandObjects.functionLoadReplace(functionCode)); } @Override - public Response functionLoad(String engineName, String libraryName, FunctionLoadParams params, String functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + public Response functionLoadReplace(String functionCode) { + return appendCommand(commandObjects.functionLoadReplace(functionCode)); } @Override diff --git a/src/main/java/redis/clients/jedis/TransactionBase.java b/src/main/java/redis/clients/jedis/TransactionBase.java index c51ecb5856..20f36dd6f5 100644 --- a/src/main/java/redis/clients/jedis/TransactionBase.java +++ b/src/main/java/redis/clients/jedis/TransactionBase.java @@ -1803,23 +1803,23 @@ public Response> functionListWithCode(final byte[] libraryNamePatte } @Override - public Response functionLoad(byte[] engineName, byte[] libraryName, byte[] functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + public Response functionLoad(byte[] functionCode) { + return appendCommand(commandObjects.functionLoad(functionCode)); } @Override - public Response functionLoad(String engineName, String libraryName, String functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + public Response functionLoad(String functionCode) { + return appendCommand(commandObjects.functionLoad(functionCode)); } @Override - public Response functionLoad(byte[] engineName, byte[] libraryName, FunctionLoadParams params, byte[] functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + public Response functionLoadReplace(byte[] functionCode) { + return appendCommand(commandObjects.functionLoadReplace(functionCode)); } @Override - public Response functionLoad(String engineName, String libraryName, FunctionLoadParams params, String functionCode) { - return appendCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + public Response functionLoadReplace(String functionCode) { + return appendCommand(commandObjects.functionLoadReplace(functionCode)); } @Override diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index c7a1b26817..2e99eb46c4 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -3140,13 +3140,13 @@ public List functionListWithCode(String libraryNamePattern) { } @Override - public String functionLoad(String engineName, String libraryName, String functionCode) { - return executeCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + public String functionLoad(String functionCode) { + return executeCommand(commandObjects.functionLoad(functionCode)); } @Override - public String functionLoad(String engineName, String libraryName, FunctionLoadParams params, String functionCode) { - return executeCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + public String functionLoadReplace(String functionCode) { + return executeCommand(commandObjects.functionLoadReplace(functionCode)); } @Override @@ -3195,13 +3195,13 @@ public List functionListWithCode(final byte[] libraryNamePattern) { } @Override - public String functionLoad(byte[] engineName, byte[] libraryName, byte[] functionCode) { - return executeCommand(commandObjects.functionLoad(engineName, libraryName, functionCode)); + public String functionLoad(byte[] functionCode) { + return executeCommand(commandObjects.functionLoad(functionCode)); } @Override - public String functionLoad(byte[] engineName, byte[] libraryName, FunctionLoadParams params, byte[] functionCode) { - return executeCommand(commandObjects.functionLoad(engineName, libraryName, params, functionCode)); + public String functionLoadReplace(byte[] functionCode) { + return executeCommand(commandObjects.functionLoadReplace(functionCode)); } @Override diff --git a/src/main/java/redis/clients/jedis/commands/FunctionBinaryCommands.java b/src/main/java/redis/clients/jedis/commands/FunctionBinaryCommands.java index 3eb0fa1d8a..59eb9664d6 100644 --- a/src/main/java/redis/clients/jedis/commands/FunctionBinaryCommands.java +++ b/src/main/java/redis/clients/jedis/commands/FunctionBinaryCommands.java @@ -2,7 +2,6 @@ import redis.clients.jedis.args.FlushMode; import redis.clients.jedis.args.FunctionRestorePolicy; -import redis.clients.jedis.params.FunctionLoadParams; import redis.clients.jedis.resps.FunctionStats; import redis.clients.jedis.resps.LibraryInfo; @@ -89,22 +88,21 @@ public interface FunctionBinaryCommands { /** * Load a library to Redis. - * @param engineName the name of the execution engine for the library - * @param libraryName the unique name of the library - * @param functionCode the source code - * @return OK + * @param functionCode the source code. The library payload must start + * with Shebang statement that provides a metadata + * about the library (like the engine to use and the library name). + * Shebang format: #! name=. + * Currently engine name must be lua. + * @return The library name that was loaded */ - String functionLoad(byte[] engineName, byte[] libraryName, byte[] functionCode); + String functionLoad(byte[] functionCode); /** - * Load a library to Redis. - * @param engineName the name of the execution engine for the library - * @param libraryName the unique name of the library - * @param params {@link FunctionLoadParams} + * Load a library to Redis. Will replace the current library if it already exists. * @param functionCode the source code - * @return OK + * @return The library name that was loaded */ - String functionLoad(byte[] engineName, byte[] libraryName, FunctionLoadParams params, byte[] functionCode); + String functionLoadReplace(byte[] functionCode); /** * Restore libraries from the serialized payload. Default policy is APPEND. diff --git a/src/main/java/redis/clients/jedis/commands/FunctionCommands.java b/src/main/java/redis/clients/jedis/commands/FunctionCommands.java index c89a8e70af..2a918d9482 100644 --- a/src/main/java/redis/clients/jedis/commands/FunctionCommands.java +++ b/src/main/java/redis/clients/jedis/commands/FunctionCommands.java @@ -2,7 +2,6 @@ import redis.clients.jedis.args.FlushMode; import redis.clients.jedis.args.FunctionRestorePolicy; -import redis.clients.jedis.params.FunctionLoadParams; import redis.clients.jedis.resps.FunctionStats; import redis.clients.jedis.resps.LibraryInfo; @@ -93,22 +92,21 @@ public interface FunctionCommands { /** * Load a library to Redis. - * @param engineName the name of the execution engine for the library - * @param libraryName the unique name of the library - * @param functionCode the source code - * @return OK + * @param functionCode the source code. The library payload must start + * with Shebang statement that provides a metadata + * about the library (like the engine to use and the library name). + * Shebang format: #! name=. + * Currently engine name must be lua. + * @return The library name that was loaded */ - String functionLoad(String engineName, String libraryName, String functionCode); + String functionLoad(String functionCode); /** - * Load a library to Redis. - * @param engineName the name of the execution engine for the library - * @param libraryName the unique name of the library - * @param params {@link FunctionLoadParams} + * Load a library to Redis. Will replace the current library if it already exists. * @param functionCode the source code - * @return OK + * @return The library name that was loaded */ - String functionLoad(String engineName, String libraryName, FunctionLoadParams params, String functionCode); + String functionLoadReplace(String functionCode); /** * Restore libraries from the serialized payload. Default policy is APPEND. diff --git a/src/main/java/redis/clients/jedis/commands/FunctionPipelineBinaryCommands.java b/src/main/java/redis/clients/jedis/commands/FunctionPipelineBinaryCommands.java index d39e96047c..700e892ec8 100644 --- a/src/main/java/redis/clients/jedis/commands/FunctionPipelineBinaryCommands.java +++ b/src/main/java/redis/clients/jedis/commands/FunctionPipelineBinaryCommands.java @@ -3,7 +3,6 @@ import redis.clients.jedis.Response; import redis.clients.jedis.args.FlushMode; import redis.clients.jedis.args.FunctionRestorePolicy; -import redis.clients.jedis.params.FunctionLoadParams; import java.util.List; @@ -31,9 +30,9 @@ public interface FunctionPipelineBinaryCommands { Response> functionListWithCode(byte[] libraryNamePattern); - Response functionLoad(byte[] engineName, byte[] libraryName, byte[] functionCode); + Response functionLoad(byte[] functionCode); - Response functionLoad(byte[] engineName, byte[] libraryName, FunctionLoadParams params, byte[] functionCode); + Response functionLoadReplace(byte[] functionCode); Response functionRestore(byte[] serializedValue); diff --git a/src/main/java/redis/clients/jedis/commands/FunctionPipelineCommands.java b/src/main/java/redis/clients/jedis/commands/FunctionPipelineCommands.java index 3e9984b8ed..99588d00fd 100644 --- a/src/main/java/redis/clients/jedis/commands/FunctionPipelineCommands.java +++ b/src/main/java/redis/clients/jedis/commands/FunctionPipelineCommands.java @@ -3,7 +3,6 @@ import redis.clients.jedis.Response; import redis.clients.jedis.args.FlushMode; import redis.clients.jedis.args.FunctionRestorePolicy; -import redis.clients.jedis.params.FunctionLoadParams; import redis.clients.jedis.resps.FunctionStats; import redis.clients.jedis.resps.LibraryInfo; @@ -33,9 +32,9 @@ public interface FunctionPipelineCommands { Response> functionListWithCode(String libraryNamePattern); - Response functionLoad(String engineName, String libraryName, String functionCode); + Response functionLoad(String functionCode); - Response functionLoad(String engineName, String libraryName, FunctionLoadParams params, String functionCode); + Response functionLoadReplace(String functionCode); Response functionRestore(byte[] serializedValue); diff --git a/src/main/java/redis/clients/jedis/params/FunctionLoadParams.java b/src/main/java/redis/clients/jedis/params/FunctionLoadParams.java deleted file mode 100644 index b2b64c044e..0000000000 --- a/src/main/java/redis/clients/jedis/params/FunctionLoadParams.java +++ /dev/null @@ -1,41 +0,0 @@ -package redis.clients.jedis.params; - -import static redis.clients.jedis.Protocol.Keyword.REPLACE; -import static redis.clients.jedis.Protocol.Keyword.DESCRIPTION; - -import redis.clients.jedis.CommandArguments; - -public class FunctionLoadParams implements IParams { - private boolean replace = false; - private String description; - - public FunctionLoadParams() { } - - /** - * overwrites the existing library with the new contents - */ - public FunctionLoadParams replace() { - this.replace = true; - return this; - } - - /** - * attach a description to the library - */ - public FunctionLoadParams libraryDescription(String desc) { - this.description = desc; - return this; - } - - @Override - public void addParams(CommandArguments args) { - if (this.replace) { - args.add(REPLACE); - } - - if (this.description != null) { - args.add(DESCRIPTION); - args.add(this.description); - } - } -} diff --git a/src/main/java/redis/clients/jedis/resps/LibraryInfo.java b/src/main/java/redis/clients/jedis/resps/LibraryInfo.java index 89451bdd18..7934ce7080 100644 --- a/src/main/java/redis/clients/jedis/resps/LibraryInfo.java +++ b/src/main/java/redis/clients/jedis/resps/LibraryInfo.java @@ -13,18 +13,16 @@ public class LibraryInfo { private final String libraryName; private final String engine; - private final String description; private final List> functions; private final String libraryCode; - public LibraryInfo(String libraryName, String engineName, String description, List> functions) { - this(libraryName, engineName, description, functions, null); + public LibraryInfo(String libraryName, String engineName, List> functions) { + this(libraryName, engineName, functions, null); } - public LibraryInfo(String libraryName, String engineName, String description, List> functions, String code) { + public LibraryInfo(String libraryName, String engineName, List> functions, String code) { this.libraryName = libraryName; this.engine = engineName; - this.description = description; this.functions = functions; this.libraryCode = code; } @@ -37,10 +35,6 @@ public String getEngine() { return engine; } - public String getDescription() { - return description; - } - public List> getFunctions() { return functions; } @@ -55,14 +49,13 @@ public LibraryInfo build(Object data) { List objectList = (List) data; String libname = STRING.build(objectList.get(1)); String engine = STRING.build(objectList.get(3)); - String desc = STRING.build(objectList.get(5)); - List rawFunctions = (List) objectList.get(7); + List rawFunctions = (List) objectList.get(5); List> functions = rawFunctions.stream().map(o -> ENCODED_OBJECT_MAP.build(o)).collect(Collectors.toList()); - if (objectList.size() <= 8) { - return new LibraryInfo(libname, engine, desc, functions); + if (objectList.size() <= 6) { + return new LibraryInfo(libname, engine, functions); } - String code = STRING.build(objectList.get(9)); - return new LibraryInfo(libname, engine, desc, functions, code); + String code = STRING.build(objectList.get(7)); + return new LibraryInfo(libname, engine, functions, code); } }; diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ScriptingCommandsTest.java index d88e26d8a2..5c5a15425e 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ScriptingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ScriptingCommandsTest.java @@ -20,7 +20,6 @@ import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.exceptions.JedisNoScriptException; -import redis.clients.jedis.params.FunctionLoadParams; import redis.clients.jedis.resps.FunctionStats; import redis.clients.jedis.resps.LibraryInfo; import redis.clients.jedis.util.ClientKillerUtil; @@ -326,15 +325,16 @@ public void functionLoadAndDelete() { String engine = "Lua"; String library = "mylib"; String function = "redis.register_function('myfunc', function(keys, args) return args[1] end)"; + String functionCode = String.format("#!%s name=%s \n %s", engine, library, function); - assertEquals("OK", jedis.functionLoad(engine, library, function)); - assertEquals("OK", jedis.functionLoad(engine, library, new FunctionLoadParams().replace().libraryDescription(""), function)); + assertEquals(library, jedis.functionLoad(functionCode)); + assertEquals(library, jedis.functionLoadReplace(functionCode)); assertEquals("OK", jedis.functionDelete(library)); // Binary - assertEquals("OK", jedis.functionLoad(engine.getBytes(), library.getBytes(), function.getBytes())); - assertEquals("OK", jedis.functionLoad(engine.getBytes(), library.getBytes(), new FunctionLoadParams().replace(), function.getBytes())); + assertEquals(library, jedis.functionLoad(functionCode.getBytes())); + assertEquals(library, jedis.functionLoadReplace(functionCode.getBytes())); assertEquals("OK", jedis.functionDelete(library.getBytes())); } @@ -344,12 +344,13 @@ public void functionFlush() { String engine = "Lua"; String library = "mylib"; String function = "redis.register_function('myfunc', function(keys, args) return args[1] end)"; + String functionCode = String.format("#!%s name=%s \n %s", engine, library, function); - assertEquals("OK", jedis.functionLoad(engine, library, function)); + assertEquals(library, jedis.functionLoad(functionCode)); jedis.functionFlush(); - assertEquals("OK", jedis.functionLoad(engine, library, function)); + assertEquals(library, jedis.functionLoad(functionCode)); jedis.functionFlush(FlushMode.ASYNC); - assertEquals("OK", jedis.functionLoad(engine, library, function)); + assertEquals(library, jedis.functionLoad(functionCode)); jedis.functionFlush(FlushMode.SYNC); } @@ -358,12 +359,12 @@ public void functionList() { String engine = "LUA"; String library = "mylib"; String function = "redis.register_function('myfunc', function(keys, args) return args[1] end)"; - jedis.functionLoad(engine, library, new FunctionLoadParams().libraryDescription("test"), function); + String functionCode = String.format("#!%s name=%s \n %s", engine, library, function); + jedis.functionLoad(functionCode); LibraryInfo response = jedis.functionList().get(0); assertEquals(library, response.getLibraryName()); assertEquals(engine, response.getEngine()); - assertEquals("test", response.getDescription()); assertEquals(1, response.getFunctions().size()); // check function info @@ -375,7 +376,7 @@ public void functionList() { // check WITHCODE response = jedis.functionListWithCode().get(0); assertEquals("myfunc", func.get("name")); - assertEquals(function, response.getLibraryCode()); + assertEquals(functionCode, response.getLibraryCode()); // check with LIBRARYNAME response = jedis.functionList(library).get(0); @@ -384,7 +385,7 @@ public void functionList() { // check with code and with LIBRARYNAME response = jedis.functionListWithCode(library).get(0); assertEquals(library, response.getLibraryName()); - assertEquals(function, response.getLibraryCode()); + assertEquals(functionCode, response.getLibraryCode()); // Binary List bresponse = (List) jedis.functionListBinary().get(0); @@ -408,7 +409,7 @@ public void functionDumpRestore() { String library = "mylib"; String function = "redis.register_function('myfunc', function(keys, args) return args[1] end)"; - jedis.functionLoad(engine, library, function); + jedis.functionLoad(String.format("#!%s name=%s \n %s", engine, library, function)); byte[] payload = jedis.functionDump(); jedis.functionFlush(); assertEquals("OK", jedis.functionRestore(payload)); @@ -427,7 +428,7 @@ public void functionStatsWithoutRunning() { String library = "mylib"; String function = "redis.register_function('myfunc', function(keys, args) return args[1] end)"; - jedis.functionLoad(engine, library, function); + jedis.functionLoad(String.format("#!%s name=%s \n %s", engine, library, function)); FunctionStats stats = jedis.functionStats(); assertNull(stats.getRunningScript()); assertEquals(1, stats.getEngines().size()); @@ -438,7 +439,7 @@ public void functionStatsWithoutRunning() { // jedis.functionFlush(); // function = "redis.register_function('myfunc', function(keys, args)\n local a = 1 while true do a = a + 1 end \nend)"; // -// jedis.functionLoad(engine, library, function); +// jedis.functionLoad(String.format("#!%s name=%s \n %s", engine, library, function)); // jedis.fcall("myfunc", new ArrayList<>(), new ArrayList<>()); // stats = jedis.functionStats(); // assertNotNull(stats.getScript()); @@ -451,7 +452,7 @@ public void functionStatsWithoutRunning() { // String library = "mylib"; // String function = "redis.register_function('myfunc', function(keys, args)\n local a = 1 while true do a = a + 1 end \nend)"; // -// jedis.functionLoad(engine, library, function); +// jedis.functionLoad(String.format("#!%s name=%s \n %s", engine, library, function)); // jedis.fcall("myfunc", Collections.emptyList(), Collections.emptyList()); // assertEquals("OK", jedis.functionKill()); // } @@ -462,7 +463,7 @@ public void functionKillWithoutRunningFunction() { String library = "mylib"; String function = "redis.register_function('myfunc', function(keys, args)\n local a = 1 while true do a = a + 1 end \nend)"; - jedis.functionLoad(engine, library, function); + jedis.functionLoad(String.format("#!%s name=%s \n %s", engine, library, function)); try { jedis.functionKill(); fail("Should get NOTBUSY error."); @@ -477,7 +478,7 @@ public void fcall() { String library = "mylib"; String function = "redis.register_function('myfunc', function(keys, args) return args end)"; - jedis.functionLoad(engine, library, function); + jedis.functionLoad(String.format("#!%s name=%s \n %s", engine, library, function)); List args = Arrays.asList("hello"); assertEquals(args, jedis.fcall("myfunc", Collections.emptyList(), args)); } @@ -488,7 +489,7 @@ public void fcallBinary() { String library = "mylib"; String function = "redis.register_function('myfunc', function(keys, args) return args[1] end)"; - jedis.functionLoad(engine, library, function); + jedis.functionLoad(String.format("#!%s name=%s \n %s", engine, library, function)); List bargs = Arrays.asList("hello".getBytes()); assertArrayEquals("hello".getBytes(), (byte[]) jedis.fcall("myfunc".getBytes(), Collections.emptyList(), bargs)); } @@ -498,7 +499,7 @@ public void fcallReadonly() { String engine = "Lua"; String library = "mylib"; String function = "redis.register_function{function_name='noop', callback=function() return 1 end, flags={ 'no-writes' }}"; - jedis.functionLoad(engine, library, function); + jedis.functionLoad(String.format("#!%s name=%s \n %s", engine, library, function)); assertEquals(Long.valueOf(1), jedis.fcallReadonly("noop", Collections.emptyList(), Collections.emptyList()));