Skip to content

Instantly share code, notes, and snippets.

@un-def
Created January 27, 2021 15:55
Show Gist options
  • Save un-def/82d80ab525383cdb2ed868bb984e717a to your computer and use it in GitHub Desktop.
Save un-def/82d80ab525383cdb2ed868bb984e717a to your computer and use it in GitHub Desktop.
local tcp_sock_mt = getmetatable(ngx.socket.tcp())
local udp_sock_mt = getmetatable(ngx.socket.udp())
local is_socket_object = function(obj)
local obj_mt = getmetatable(obj)
return obj_mt == tcp_sock_mt or obj_mt == udp_sock_mt
end
--------
local redis = require('resty.redis')
local client = redis:new()
ngx.say(is_socket_object(client)) -- false
ngx.say(is_socket_object('string')) -- false
ngx.say(is_socket_object(client._sock)) -- true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment