Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding thread_id api call #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Table of Contents
* [read_result](#read_result)
* [query](#query)
* [server_ver](#server_ver)
* [thread_id](#thread_id)
* [set_compact_arrays](#set_compact_arrays)
* [SQL Literal Quoting](#sql-literal-quoting)
* [Multi-Resultset Support](#multi-resultset-support)
Expand Down Expand Up @@ -332,6 +333,16 @@ You should only call this method after successfully connecting to a MySQL server

[Back to TOC](#table-of-contents)

thread_id
----------
`syntax: tid = db:thread_id()`

Returns the MySQL connection thread id, like `"758"`.

You should only call this method after successfully connecting to a MySQL server, otherwise `nil` will be returned.

[Back to TOC](#table-of-contents)

set_compact_arrays
------------------
`syntax: db:set_compact_arrays(boolean)`
Expand Down
5 changes: 5 additions & 0 deletions lib/resty/mysql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ function _M.connect(self, opts)
self._server_ver = server_ver

local thread_id, pos = _get_byte4(packet, pos)

self._thread_id = thread_id

--print("thread id: ", thread_id)

Expand Down Expand Up @@ -694,6 +696,9 @@ function _M.server_ver(self)
return self._server_ver
end

function _M.thread_id(self)
return self._thread_id
end

local function send_query(self, query)
if self.state ~= STATE_CONNECTED then
Expand Down
4 changes: 2 additions & 2 deletions t/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ GET /t
return
end

ngx.say("connected to mysql ", db:server_ver())
ngx.say("connected to mysql ", db:server_ver(), " thread ", db:thread_id())

db:close()
';
}
--- request
GET /t
--- response_body_like
connected to mysql \d\.\S+
connected to mysql \d\.\S+\sthread\s\d+
--- no_error_log
[error]

Expand Down