From a1f74f5bd95d1b42f490a4a7337c49d7f8551b40 Mon Sep 17 00:00:00 2001 From: tanlanxing Date: Fri, 29 Apr 2016 17:46:48 +0800 Subject: [PATCH] ngx.worker.pid method is more efficient than ngx.var.pid and can be used in contexts where the ngx.var.VARIABLE API cannot be used (like init_worker_by_lua), see: https://github.com/openresty/lua-nginx-module#ngxworkerpid --- lib/resty/mongol/object_id.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resty/mongol/object_id.lua b/lib/resty/mongol/object_id.lua index 6673795..af9b081 100755 --- a/lib/resty/mongol/object_id.lua +++ b/lib/resty/mongol/object_id.lua @@ -53,7 +53,7 @@ else end machineid = ngx.md5_bin(machineid):sub(1, 3) -local pid = num_to_le_uint(bit.band(ngx.var.pid, 0xFFFF), 2) +local pid = num_to_le_uint(bit.band(ngx.worker.pid(), 0xFFFF), 2) local inc = 0 local function generate_id ( )