From 8a69b179d8c390ea7de5b8f687f71b42eaed4706 Mon Sep 17 00:00:00 2001 From: Marco Capetta Date: Tue, 13 Aug 2019 17:53:25 +0200 Subject: [PATCH] TT#65050 Add additional functions to recentcall.lua Added: * set_element_by_key * get_element_by_key Change-Id: I50009ecbc51ecae08dd055d2a099b2cffca82c3c --- ngcp/recentcalls.lua | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/ngcp/recentcalls.lua b/ngcp/recentcalls.lua index 1cee119..b4fe849 100644 --- a/ngcp/recentcalls.lua +++ b/ngcp/recentcalls.lua @@ -47,7 +47,8 @@ end port = 6379, db = "7" }, - expire = 7200 + expire = 7200, + out_expire = 86400 }, central = {}, }; @@ -97,6 +98,38 @@ end return res end + function NGCPRecentCalls:set_element_by_key(key, element, value) + if not self._test_connection(self.central) then + self.central = self._connect(self.config.central) + end + + local res = self.central:hmset(key, element, value) + if res then + self.central:expire(key, self.config.out_expire) + end + sr.log("info", string.format("central:hset[%s]=>[%s] %s: %s expire: %d\n", + key, tostring(res), + element, tostring(value), + self.config.out_expire)) + return res + end + + function NGCPRecentCalls:get_element_by_key(key, element) + if not self._test_connection(self.central) then + self.central = self._connect(self.config.central) + end + + local res = self.central:hgetall(key) + if res then + sr.log("info", string.format("central:hget[%s]=>[%s]\n", + key, tostring(res[element]))) + + return res[element] + end + + return 0 + end + -- class return NGCPRecentCalls