Aerospike C Client Manual ——— user-defined functions-register user-defined Functions

Source: Internet
Author: User

Registering user-defined functions

The Aerospike C client provides the ability to register, update, or remove a user-defined function (UDF) module in the database. Currently, user-defined functions only support the LUA language.

    • aerospike_udf_put()-Register or update the UDF module.
    • aerospike_udf_remove()-Remove the UDF module.

The following code references the sample directory from the " examples/basic_examples/udf " , comes with the Aerospike C client installation package.

Please read the section "Creating connections" to understand how to establish a connection to a cluster.

Read UDF from File

It is possible that the module you are trying to register is saved in a file. So read into this file first:

file* file = fopen ("Myudf.lua","R");if(! file) {LOG ("Cannot open script file%s:%s", Udf_file_path, Strerror (errno));return false;}//Read The file ' s content into a local buffer.uint8_t* content = (uint8_t*)malloc(1024x768*1024x768);if(! Content) {LOG ("Script content allocation failed");return false;} uint8_t* p_write = content;intRead = (int) Fread (P_write,1, +, file);intSize =0; while(read)    {size + = read;    P_write + = read; Read = (int) Fread (P_write,1, +, file);} fclose (file);//Wrap The local buffer as an As_bytes object.As_bytes udf_content;as_bytes_init_wrap (&udf_content, content, size,true);
Registering UDFs with the Aerospike server


< Span style= "font-family: Microsoft Jas Black" >as_error err; //Register the UDF file in the database cluster.  if  (Aerospike_udf_put (&as, &err, NULL,  "myudf"  , As_udf_type_lua, &udf_content)! = AEROSPIKE_OK) {LOG (" Aerospike_udf_put () returned%d-%s ", Err.code, err.message);} //This frees the local buffer.  As_bytes_destroy (&udf_content); 

This call sends a UDF module to a node in the cluster. This node propagates the UDF to other nodes in the cluster.

If at any time you need to update the UDF feature, simply re-register the new copy with the same module name.

Typically, UDF registration can be registered to all nodes in the cluster in just a few seconds.

Check that the UDF module is registered correctly

The best way to check if the UDF module is properly registered is by using the AQL tool. See the AQL Manual.

Remove UDF from server

If at any time the server no longer needs a UDF module, you can remove it from the cluster.

as_error err;if (aerospike_udf_remove(&as, &err, NULL, "myudf") != AEROSPIKE_OK) { LOG("aerospike_udf_remove() returned %d - %s", err.code, err.message); return false;}

original link: http://www.aerospike.com/docs/client/c/usage/udf/register.html Translator: crooked Neck belly Q  

Aerospike C Client Manual ——— user-defined functions-register user-defined Functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.