-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathredisFiller.txt
25 lines (19 loc) · 2.43 KB
/
redisFiller.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
HMSET phoneNumber:919503338275 customerId 7045 carrierId 1234 countryId 1 billType 1 channels 2 rtpProxied 1 routStrat 1
SADD carrierIPAddrs:1234 198.24.63.4
HMSET directRoute:919503338275 dstUri 919503338275 dnis 919503338275
HMSET directRoute:919503338275 dstUri 203.153.53.180:5060 dnis 919503338275
SADD carrierEndpoints:1234 203.153.53.180:5060
HMSET customer:7045 routeId 23456 balance 700
ZADD routes:23456:0 1 carrierId
HMSET carrierRates:1234:37 91 0.3456 919 0.3456
HMSET dialCode:9195 destName IND-MOBILE dstListId 37
script load "local function split(s, delimiter) local result = {}; for match in (s..delimiter):gmatch('(.-)'..delimiter) do table.insert(result, match); end return result; end local function custom(number,carrierId,dstLstId) for i = 7, 1, -1 do local prefix = string.sub(number, 1, i); local carrierRate = redis.call('HMGET', 'carrierRates:' .. carrierId .. ':' .. dstLstId, prefix); local carrierRatesize = table.maxn(carrierRate) if carrierRatesize~=nil and carrierRate[1]~=false and carrierRate[1]~=nil then return carrierRate[1]..':'..prefix end end end local routeId = ARGV[1] local dstLstId = ARGV[2] local position = ARGV[3] local number = ARGV[4] local carrierRates = {} local mytable ={} local newtable = {} local carrierId = redis.call('ZRANGEBYSCORE', 'routes:' .. routeId .. ':' .. dstLstId, position, position) local size = table.maxn(carrierId) local d=1 while size>0 do carrierRates[d]=custom(number,carrierId[size],dstLstId) if type(carrierRates[d])~='nil' then mytable[1]= carrierId[size] local splitdata=split(carrierRates[d],':') mytable[2]=splitdata[1] mytable[3]=splitdata[2] newtable[d]=mytable mytable={} d=d+1 end size=size-1 end table.sort(newtable, function(a, b) return a[2] < b[2] end) local sorted= {} for k,v in ipairs(newtable) do sorted[k]=v[1]..':'..v[2]..':'..v[3] end return sorted"
HMSET phoneNumber:23418889700 customerId 2222 carrierId 1111 countryId 1 billType 1 channels 2 rtpProxied 1 routStrat 1
HMSET phoneNumber:23418889701 customerId 2222 carrierId 1111 countryId 1 billType 1 channels 2 rtpProxied 1 routStrat 1
SADD carrierIPAddrs:1111 188.244.114.8 203.153.53.130
HMSET directRoute:23418889700 dstUri 14703993047 dnis 14703993047
HMSET directRoute:23418889701 dstUri 14703993047 dnis 14703993047
HMSET customer:2222 routeId 3333 balance 700
ZADD routes:3333:0 1 4444
SADD carrierEndpoints:4444 178.62.27.239:5060
HMSET carrierRates:4444:0 14703993047 0.77