1
我尝试删除和修剪列表,以建立一个分页系统下降和修剪在塞UDF列表
local function createMap(postId, paramDate)
local m = map { id = postId, date = paramDate };
return m;
end
function get(rec, binName, from, to)
if aerospike:exists(rec) then
local l = rec[binName]
if (l == nil) then
return nil
else
local length = #l;
if (length <= 10 and to <=10) then
return l;
elseif (to >= length) then
local drop = list.drop(l, from);
return drop;
else
list.trim(l, to);--Remove all elements at and beyond a specified position in the List.
list.drop(l, from); --Select all elements except the first n elements of the List
return l;
end
end
else
return nil;--end return empty array
end--end else aerospike exists
end
我的列表中有这样的结构:
[{"date":"2016-01-02T19:45:00.806Z", "id":"568828bc49017f16659f6978"}, {"date":"2016-01-02T19:44:56.040Z", "id":"568828b849017f16659f6977"},...]
看来,我可以”修剪,然后删除一个列表。例如有21个元素:它首先返回到元素21到元素13,然后元素21到元素4,然后元素3到元素1
我在node.js中的函数很简单,用于更改'from'和'to'我发送“页”弗罗姆前端到的node.js和使用此功能:
var skip = 9 * (page -1);
var lastIndexToReturn = skip + 9 + 1;
所以在第一请求从和到是“0”和“10”,则“9”和“19”,等 使用list.trim和list.drop我认为我可以建立一个分页系统
是你的列表记录足够小,规模有限正常列表的符合你的用例吗?对于无限列表,Aerospike拥有大型有序列表。有没有方法来建立没有UDF的分页(更高性能),你会对这样的答案感兴趣吗?我知道你正在使用node.js客户端?干杯 –
这是一个清单,约600名elelents ...我只使用一个bin和这个结构,所以它是在128kb ...确实是使用node.js ...如果你有更好的方法,我会高兴地知道它......但我也知道为什么这个代码dosn't工作?顺便说一句,我akso尝试与largelist:http://stackoverflow.com/questions/34564418/sort-an-array-of-associatives-arrays-in-lua?noredirect=1#comment56891437_34564418 – moubert
我也建立了分页节点,我在比较日期和切片排序数组......但我认为在lua做整个工作会更好吗? – moubert