0

I am using this file, but its not working. What am I doing wrong

function lines_from(file)
  if not file_exists(file) then return {} end
  local lines = {}
  for line in io.lines(file) do 
    lines[#lines + 1] = line
  end
  return lines
end

-- tests the functions above
local file = 'a.txt'
local lines = lines_from(file)

-- iterate all line numbers and delete key
for k,v in pairs(lines) do
  redis.call('DEL', v)
end

Is file iteration wrong or keys always needs to be passed in argument. I have 1000 keys to delete Keys dont have any prefix and cant regex as no pattern

Dev Dev
  • 55
  • 1
  • 7
  • Can you please define "Not working". Is lines empty? Does the file exist? Line 2 may return an empty table. – Luke100000 Sep 25 '22 at 20:22

1 Answers1

0

I'd assume the line count being 0 has something to do with it "not working". If it's not passing an error, it could potentially contain no values at all.

if #lines == 0 then
    return error("An error occurred opening the file: Missing lines")
end
kryozor
  • 315
  • 1
  • 7