我想在lua中有一個簡單的數據結構,類似於Java HashMap等價物。如何在Lua中創建等價的HashMap <Int, Int[]>
這樣做的目的是,我希望保持一個唯一的鍵'userID'映射一組兩個不斷更新的值,例如;
'77777', {254, 24992}
有關如何實現此目的的任何建議?
-- Individual Aggregations
local dictionary = ?
-- Other Vars
local sumCount = 0
local sumSize = 0
local matches = redis.call(KEYS, query)
for _,key in ipairs(matches) do
local val = redis.call(GET, key)
local count, size = val:match(([^:]+):([^:]+))
topUsers(string.sub(key, 11, 15), sumCount, sumSize)
-- Global Count and Size for the Query
sumCount = sumCount + tonumber(count)
sumSize = sumSize + tonumber(size)
end
local result = string.format(%s:%s, sumCount, sumSize)
return result;
-- Users Total Data Aggregations
function topUsers()
-- Do sums for each user
end
嘗試這樣 私有靜態最後字符串READ_SCRIPT_IN_LUA = 「本地詞典= {」 + 「[ '77777'] = {254,24992},」 + 「[ '88888'] = {253, 24991},「+ 」['99999'] = {252,24990}「+ 」}「+ 」return dictionary「; Object o = jedis.eval(String.format(READ_SCRIPT_IN_LUA)); System.out.println(o.toString()); 輸出:[] 我做錯了什麼? –