summaryrefslogtreecommitdiffstats
path: root/iredis/data/commands/function-load.md
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-04 07:19:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-04 07:19:32 +0000
commit7480e618ec785ba8a1c74c8a150cffe5880fb3bb (patch)
tree87422376dd9a7eee55850f0fce9a8bb4c13e44a2 /iredis/data/commands/function-load.md
parentAdding upstream version 1.12.1. (diff)
downloadiredis-df49d7c38b2b8498c93215691d16403b32becec8.tar.xz
iredis-df49d7c38b2b8498c93215691d16403b32becec8.zip
Adding upstream version 1.13.0.upstream/1.13.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'iredis/data/commands/function-load.md')
-rw-r--r--iredis/data/commands/function-load.md36
1 files changed, 36 insertions, 0 deletions
diff --git a/iredis/data/commands/function-load.md b/iredis/data/commands/function-load.md
new file mode 100644
index 0000000..16f125b
--- /dev/null
+++ b/iredis/data/commands/function-load.md
@@ -0,0 +1,36 @@
+Load a library to Redis.
+
+The command's gets a single mandatory parameter which is the source code that implements the library.
+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: `#!<engine name> name=<library name>`. Currently engine name must be `lua`.
+
+For the Lua engine, the implementation should declare one or more entry points to the library with the [`redis.register_function()` API](/topics/lua-api#redis.register_function).
+Once loaded, you can call the functions in the library with the `FCALL` (or `FCALL_RO` when applicable) command.
+
+When attempting to load a library with a name that already exists, the Redis server returns an error.
+The `REPLACE` modifier changes this behavior and overwrites the existing library with the new contents.
+
+The command will return an error in the following circumstances:
+
+* An invalid _engine-name_ was provided.
+* The library's name already exists without the `REPLACE` modifier.
+* A function in the library is created with a name that already exists in another library (even when `REPLACE` is specified).
+* The engine failed in creating the library's functions (due to a compilation error, for example).
+* No functions were declared by the library.
+
+For more information please refer to [Introduction to Redis Functions](/topics/functions-intro).
+
+@return
+
+@string - the library name that was loaded
+
+@examples
+
+The following example will create a library named `mylib` with a single function, `myfunc`, that returns the first argument it gets.
+
+```
+redis> FUNCTION LOAD "#!lua name=mylib \n redis.register_function('myfunc', function(keys, args) return args[1] end)"
+mylib
+redis> FCALL myfunc 0 hello
+"hello"
+```