如何处理 Aerospike 脚本中的重复项
2018-10-15 7:7:33
收藏:0
阅读:100
评论:1
我有一份脚本,它运行良好,但我需要更新它。脚本现在会添加项目而不进行任何检查以查看是否已存在。
function put_page(rec, id, val)
local l = rec['h']
if l==nil then l = list() rec['id'] = id end
list.append(l, val)
rec['h'] = l
if aerospike:exists(rec) then aerospike:update(rec) else aerospike:create(rec) end
end
我尝试使用 for value in list.iterator(l) 迭代列表并在 value ~= val 时添加项目,但它不起作用。 该函数中的 ID 是 solr 文档 _id,val 是用户 _id。我从 Aerospike 得到了示例对象:(('contextChannel', 'ContextChannel', None, bytearray(b'E\xfb\xa3\xd0\r\xd6\r\J@f\xa8\xf6>y!\xd18=\x9b')), {'ttl': 2592000, 'gen': 8}, {'id': 'ALKSD4EW', 'h': []})
更新 我尝试了不同的变体,这个是可行的:
function put_page(rec, id, val)
local l = rec['h']
local count = 0
if l==nil then l = list() rec['id'] = id end
for value in list.iterator(l) do
if (value ~= val) then count = count + 1 end
end
if (list.size(l) == count) then list.append(l, val) end
rec['h'] = l
if aerospike:exists(rec) then aerospike:update(rec) else aerospike:create(rec) end
end
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

不要为已经存在 List API 操作的内容创建 UDF。UDF 的性能和伸缩性都不如 List API 好。
你可以不使用 UDF 来完成这个操作。以下是使用 Python 客户端 实现相同操作的示例代码。
from aerospike_helpers.operations import list_operations as lh from aerospike_helpers.operations import operations as oh list_policy = { "list_order": aerospike.LIST_UNORDERED, "write_flags": (aerospike.LIST_WRITE_ADD_UNIQUE | aerospike.LIST_WRITE_NO_FAIL) } ops = [ oh.write('id', id), lh.list_append('h', val, list_policy) ] client.operate(key, ops)我在 rbotzer/aerospike-cdt-examples 中也有类似的示例。