Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hqzxzb/lua-resty-unique-id

Lua library for generating a unique ID for OpenResty
https://github.com/hqzxzb/lua-resty-unique-id

Last synced: 2 months ago
JSON representation

Lua library for generating a unique ID for OpenResty

Awesome Lists containing this project

README

        

# 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``` :

```lua
--Load Unique ID library and initialize
require("unique_id");
unique_id.init();
```

2. Use Unique ID library in your Lua script :

```lua
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.**