Manage UDFs
Register
To register UDFs, you must first group them in a module and then register that UDF module with the Aerospike server cluster using Client.register_udf:
# To automatically read the a UDF source filedef register_udf_from_file(client_path, server_path, language=Aerospike::Language::LUA, options={})
# Supply the UDF source as a stringdef register_udf(udf_body, server_path, language=Aerospike::Language::LUA, options={})Where:
udf_body— The UDF source.client_path— The local path to the UDF module.server_path— The UDF module to store in the cluster.language— The UDF module language.
This example registers the example.lua UDF module as a LUA language module:
task = client.register_udf_from_file("udf/example.lua", "example.lua")UDF modules register asynchronously, which means that the server can return before the UDF module is available on all nodes. The client can use wait_till_completed to wait until the asynchronous task completes:
# to block until the UDF is createdtask.wait_till_completed# task is completed successfullyOnce registration completes, the UDFs can be called from the Aerospike Ruby client.
List
Use the Aerospike Ruby client to manage a list of UDFs.
To get a list of registered UDFs on the server:
client.list_udfAn array of Aerospike::UDF objects returns with information about each UDF.
Remove
User-Defined Functions (UDFs) are grouped in a module you can remove from the server.
To remove a UDF using Client.remove_udf:
def remove_udf(udf_name, options={})Where:
udf_nameis the UDF module name.
To asynchronously delete the example.lua UDF module:
task = client.remove_udf("udf/example.lua")To block the call until the UDF is removed:
# to block until the UDF is removedtask.wait_till_completed