Lua library for generating a unique ID for OpenResty
This Lua library is a unique ID generator in OpenResty.
You can use it to generate a unique ID that will not be duplicated for your OpenResty.
(13-bit millisecond-level timestamp)-(12-bit IP address)-(6-bit Nginx Worker PID)-(3 bit Nginx Worker number)-(6-bit auto-increasing random number)
E.g : 1523881864432-010020100149-087846-000-005964
- Perform initialization in
init_by_lua
orinit_by_lua_file
:
--Load Unique ID library and initialize
require("unique_id");
unique_id.init();
- Use Unique ID library in your Lua script :
local id = unique_id.id();
Test using Apache httpd ab tool
Windows
200000 requests and 500 concurrent
No duplicate value.
Linux
200000 requests and 500 concurrent
No duplicate value.