Last active
January 1, 2016 10:19
-
-
Save agentzh/8130506 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| location /t { | |
| access_log off; | |
| content_by_lua ' | |
| local mysql = require "mysql2" | |
| local query = mysql.query | |
| local db = { | |
| _max_packet_size = 10240 | |
| } | |
| local sub = string.sub | |
| local f, err = io.open("/tmp/packet2", "r") | |
| if not f then | |
| ngx.log(ngx.ERR, "failed to open file for reading: ", err) | |
| return ngx.exit(500) | |
| end | |
| local offset | |
| local packet_data = f:read("*a") | |
| f:close() | |
| db.sock = { | |
| receive = function (sock, len) | |
| local data = sub(packet_data, offset, offset + len - 1) | |
| offset = offset + len | |
| if data == nil then | |
| return nil, "eof already" | |
| end | |
| coroutine.yield() | |
| return data | |
| end, | |
| send = function (data) | |
| return #data | |
| end | |
| } | |
| offset = 1 | |
| local res, err, errno, sqlstate | |
| for j = 1, 10 do | |
| -- offset = 1 | |
| db.state = 1 | |
| res, err, errno, sqlstate = query(db, "select * from City order by ID limit 50", 50) | |
| if not res then | |
| ngx.log(ngx.ERR, "bad result #1: ", err, ": ", errno, ": ", sqlstate, ".") | |
| return ngx.exit(500) | |
| end | |
| end | |
| for _, row in ipairs(res) do | |
| local ncols = 0 | |
| for k, v in pairs(row) do | |
| ncols = ncols + 1 | |
| end | |
| ngx.say("ncols: ", ncols) | |
| end | |
| '; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment