MT#10749 dlgcnt: add check_pair_dup option and is_in_set()

if true it will check for duplication of keys at the list of counters used
when calling set(). Added is_in_set() to check if a key is already there

Change-Id: Ib1da91dd3cdb13c537577d8e36c1a22920112ce0
changes/87/687/2
Victor Seva 11 years ago
parent b59bf13125
commit d41435695a

@ -52,7 +52,8 @@ end
host = '127.0.0.1', host = '127.0.0.1',
port = 6379, port = 6379,
db = "4" db = "4"
} },
check_pair_dup = false
}, },
central = {}, central = {},
pair = {} pair = {}
@ -85,6 +86,14 @@ end
return res; return res;
end end
function NGCPDlgCounters:is_in_set(callid, key)
if not self._test_connection(self.pair) then
self.pair = self._connect(self.config.pair);
end
local res = self.pair:lrange(callid, 0, -1);
return table.contains(res, key);
end
function NGCPDlgCounters:set(callid, key) function NGCPDlgCounters:set(callid, key)
if not self._test_connection(self.central) then if not self._test_connection(self.central) then
self.central = self._connect(self.config.central); self.central = self._connect(self.config.central);
@ -94,6 +103,9 @@ end
if not self._test_connection(self.pair) then if not self._test_connection(self.pair) then
self.pair = self._connect(self.config.pair); self.pair = self._connect(self.config.pair);
end end
if self.config.check_pair_dup and self:is_in_set(callid, key) then
sr.log("warn", string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key));
end
local pos = self.pair:lpush(callid, key); local pos = self.pair:lpush(callid, key);
sr.log("dbg", string.format("pair:lpush[%s]=>[%s] %s\n", callid, key, tostring(pos))); sr.log("dbg", string.format("pair:lpush[%s]=>[%s] %s\n", callid, key, tostring(pos)));
end end

Loading…
Cancel
Save