hqzxzb / lua-resty-unique-id

Lua library for generating a unique ID for OpenResty

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lua-resty-unique-id

Lua library for generating a unique ID for OpenResty

Description

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.

The Unique ID pattern generated by this library

(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

How to use

  1. Perform initialization in init_by_lua or init_by_lua_file :
--Load Unique ID library and initialize
require("unique_id");
unique_id.init();
  1. Use Unique ID library in your Lua script :
local id = unique_id.id();

Test Results

Test using Apache httpd ab tool


Windows

200000 requests and 500 concurrent

No duplicate value.


Linux

200000 requests and 500 concurrent

No duplicate value.

About

Lua library for generating a unique ID for OpenResty

License:Apache License 2.0


Languages

Language:Lua 100.0%