-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathscripts.txt
1 lines (1 loc) · 1.29 KB
/
scripts.txt
1
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"