Longest prefix match for double column \ Kamailio \ lua script

Hi all,

I am reading data form text file, and want to save the output to redis, each row consists of four columns

Column1: column1Value1
Column2: column2Value1
Column3: column3Value1
Column4: column4Value1

I want to be able to search for longest match for column1, if i found longest match for Column1 i will continue filter for all Column2 that are related to Column2, and the result will bell Column3 and Column4(sometimes its multiple values of column3 and column4)

Are there some data types supports things i need.

first approach:
I tried using string data structure for key ( ex: column1_column2 as key , and value is concatenated values of column3 & column4), and i ran a loop to check key by taking sub-string and removing last character.

for i = 1, maxTries 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)

           
            KSR.xlog.xinfo("trying for pattern " .. pattern .." with time: "..ddate)
            KSR.ndb_redis.redis_cmd("srvN", "GET " .. pattern, "r")
            local redisResult = KSR.pv.get("$redis(r=>value)")
        
            if redisResult ~= nil then
                KSR.xlog.xinfo("Found result in Redis for pattern " .. pattern .." with result "..redisResult)
                return
            else
                if turnToSubstring == "column1" then
                  --  KSR.xlog.xinfo("No result for pattern " .. pattern)
                    local tmpa = column1
                    tmpa = string.sub(tmpa, 1, string.len(tmpa) - 1)
                    pattern = tmpa .. "_" .. column2
                   
                  
                    turnToSubstring = "column2"
                elseif turnToSubstring == "column2" then
                  ---  KSR.xlog.xinfo("No result for pattern " .. pattern)
                    local tmpb =column2
                    tmpb = string.sub(tmpb, 1, string.len(tmpb) - 1)
                    pattern = column1 .. "_" .. tmpb
                   
                   
                    turnToSubstring = "both"
                elseif turnToSubstring == "both" then
                    column1 = string.sub(column1, 1, string.len(column1) - 1)
                    column2 = string.sub(column2, 1, string.len(column2) - 1)
                    pattern = column1 .. "_" .. column2
                    turnToSubstring = "column1"
                end
            end
        end

2nd approach:
I tried grouping into JSON , but there were two issues that Kamailio lua doesn’t support JSON and returned contains all values , not filtered one.

list:Column1Value:{[
{
Column2:value,
Column3:value,
Column4:value,
},
{
Column2:value,
Column3:value,
Column4:value,
}]

}

“list:Column1Value” is the key and value

3rd approach:
Using sets , but i cannot get set without specifying some filter, example
SADD column1Value:column2Value column3value:column4Value
SADD column1Value:column2Value2 column3value2:column4Value2
SINT Column1Value

Thanks in advance