首页  

aerospike lua udf 例子     所属分类 aerospike 浏览量 675
asdemotest.lua

function info(rec)
    local map = map()
    -- must use map = {} !!!  else return null !!!
    -- local map = {}
    map["version"] = "20210929"
    return map
end

function info2(rec,params)
    local map = map()
    map["params"] = params
    return map
end

使用amc上传lua 或者 使用 AQL 注册脚本

使用 AQL命令 直接覆盖更新 
REGISTER MODULE 'xxx.lua'
通过 SHOW MODULES 查看更新前后 hash 


LuaTest import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; import com.aerospike.client.IAerospikeClient; import com.aerospike.client.Key; import com.aerospike.client.Value; import com.aerospike.client.policy.WritePolicy; public class LuaTest { public static void main(String[] args) throws Exception { IAerospikeClient client = AsClientUtil.getClient(); System.out.println("client=" + client); String namespace = "ns1"; String dataSetName = "testset"; String packageName = "asdemotest"; String functionName = "info"; String functionName2 = "info2"; String keyStr = "asdemo_lua_test_key_"; Key key = new Key(namespace, dataSetName, keyStr); WritePolicy policy = new WritePolicy(); // String value = ""; // Object result = client.execute(policy, key, packageName, functionName, // Value.get(value)); // 不传参数 Object result = client.execute(policy, key, packageName, functionName); System.out.println(result); System.out.println(result.getClass()); Map params = new HashMap<>(); params.put("now", LocalDateTime.now().toString()); result = client.execute(policy, key, packageName, functionName2, Value.get(params)); System.out.println(result); System.out.println(result.getClass()); client.close(); } }
完整代码 https://gitee.com/dyyx/asdemo/blob/master/src/main/java/demo/LuaTest.java
aerospike中使用lua注意点 使用aql更新lua脚本

上一篇     下一篇
算法基础知识

java String indexOf 为何不使用KMP

AVL树与红黑树(RBTree)

计算机专业考研信息

栈应用之括号匹配

栈应用之表达式求值