example.lua
local socket = require 'resty.luasocket'
local sock = socket.tcp()
sock:settimeout(1000) sock:getreusedtimes(...) sock:setkeepalive(...) sock:sslhandshake(...)
local socket = require 'resty.socket'
local _M = {}
function _M.new()
local sock = socket.tcp()
return setmetatable({
sock = sock
}, {__index = _M})
end
function _M:connect(host, port)
local ok, err = self.sock:connect(host, port)
if not ok then
return nil, err
end
local times, err = self.sock:getreusedtimes() if not times then
return nil, err
elseif times == 0 then
ngx.log(ngx.DEBUG, "start using the connection")
end
end
return _M