Hello all,
If the data returned from redis is of type array, and if I want to iterate through all the elements in the array, then I have to get $redis(r=>value[x]) for each element, and a pseudo variable for each element is allocated in the memory, is that correct?
Regards,
From: Ali Taher via sr-users sr-users@lists.kamailio.org Sent: Wednesday, November 15, 2023 4:51 PM To: Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org Cc: Ali Taher ataher@vanrise.com Subject: [SR-Users] pv cache limit is going to be exceeded
Hello all,
I'm using the following Lua script to fetch data from Redis, which is in form of list:
function split(str, delimiter) for token in string.gmatch(str, "[^" .. delimiter .. "]+") do return token end end
function contains(mainString, subString) return string.find(mainString, subString, 1, true) ~= nil end
function longest_match_acode()
local currentSeconds = os.time() local milliseconds = os.clock() * 1000 local ddate = os.date("%Y-%m-%d %H:%M:%S", currentSeconds) .. string.format(".%03d", milliseconds) KSR.xlog.xinfo("starting date:" ..ddate)
local size = 0 local result
local acode = "29192" local inputbcode = "4474173" local delimiter = ":"
while size == 0 do local currentSeconds = os.time() acode = string.sub(acode, 1, string.len(acode) - 1) KSR.ndb_redis.redis_cmd("srvN", "LRANGE price:" .. acode .." 0 -1", "r") size = tonumber(KSR.pv.get("$redis(r=>size)")) end
local left = 0 local right = size - 1
while left <= right do local currentSeconds = os.time() local milliseconds = os.clock() * 1000 local ddate = os.date("%Y-%m-%d %H:%M:%S", currentSeconds) .. string.format(".%03d", milliseconds)
resultRight = tostring(KSR.pv.get("$redis(r=>value[" .. right .. "])")) resultLeft = tostring(KSR.pv.get("$redis(r=>value[" .. left .. "])"))
local bcodeLeft = split(resultLeft, delimiter) local bcodeRight = split(resultRight, delimiter)
if contains(inputbcode, bcodeRight) then KSR.xlog.xinfo("Input bcode contains bcode value from Redis: " .. resultRight .. " at index: " .. right .. " with date: " .. ddate) end
if contains(inputbcode, bcodeLeft) then KSR.xlog.xinfo("Input bcode contains bcode value from Redis: " .. resultLeft .. " at index: " .. left .. " with date: " .. ddate) end left = left + 1 right = right - 1 end local currentSeconds = os.time() local milliseconds = os.clock() * 1000 local ddate = os.date("%Y-%m-%d %H:%M:%S", currentSeconds) .. string.format(".%03d", milliseconds) KSR.xlog.xinfo("ending date:" ..ddate)
end
function ksr_request_route()
if KSR.is_INVITE() then longest_match_acode() KSR.sl.send_reply("404", "Not found"); end end
I'm getting the following warning in the log : WARNING: LUA {INVITE}: <core> [core/pvapi.c:340]: pv_cache_add(): pv cache limit is going to be exceeded - pkg memory may get filled with pv declarations I think the issue is in the following lines: resultRight = tostring(KSR.pv.get("$redis(r=>value[" .. right .. "])")) resultLeft = tostring(KSR.pv.get("$redis(r=>value[" .. left .. "])"))
the list coming from Redis has around 30k items, which I'm iterating through using value[x] which is exhausting the pv declaration as per my understanding. How to overcome this issue? Is it possible to save the list as an array variable and then iterate through that array?
Regards,