Skip to content

Instantly share code, notes, and snippets.

@hivefans
Last active March 17, 2020 02:03
Show Gist options
  • Select an option

  • Save hivefans/408864564922e6d1e8cfe9fcd9a50fd6 to your computer and use it in GitHub Desktop.

Select an option

Save hivefans/408864564922e6d1e8cfe9fcd9a50fd6 to your computer and use it in GitHub Desktop.
openresty中的lua配置调试递归显示table内容,在连接mysql,redis中可以查看table结构|-|{"files":{"example.txt":{"env":"plain"},"ngx_rPrint.lua":{"env":"plain"}},"tag":"Uncategorized"}
res,err,errcode,sqlstate=db:query("select * from user where username='test'")
if next(res) ~=nil then
rPrint(res,nil,"res----");
end
res--------table
res---- [1] ----table
res---- [1] [role_id] ----number----1
res---- [1] [username] ----string----jack
function rPrint(s, l, i) -- recursive Print (structure, limit, indent)
l = (l) or 100; i = i or ""; -- default item limit, indent string
if (l<1) then ngx.say("ERROR: Item limit reached.<br/>"); return l-1 end;
local ts = type(s);
if (ts ~= "table") then ngx.say(i.."----",ts.."----",s,"<br/>"); return l-1 end
ngx.say(i.."----",ts,"<br/>"); -- print "table"
for k,v in pairs(s) do -- print "[KEY] VALUE"
l = rPrint(v, l, i.." \t ["..tostring(k).."] ");
if (l < 0) then break end
end
return l
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment