色んな言語のユニークID発行方法のメモ

Nginx

$request_id

1
2
3
# 例
add_header X-Request-ID $request_id;
proxy_set_header X-Request-ID $request_id;

Apache

Apache モジュール mod_unique_id

PHP

PHP: uniqid

1
2
$ php -r "echo md5(uniqid(mt_rand(), true));"
9fc612874b43511a36b8a22b4d1bd02e

Ruby

1
2
3
4
5
6
7
require 'securerandom'

p SecureRandom.uuid
"8fc316f6-b547-46ed-a3a1-e687f5ae59e3"

p SecureRandom.uuid.delete('-')
"3593da334c6a4f72899e131962fbf447"

Python

1
2
3
4
5
6
7
8
import uuid

id = str(uuid.uuid1())
print(id)
17472bc6-d68f-11e8-a145-0242ac0a0064

print(id.replace('-', ''))
17472bc6d68f11e8a1450242ac0a0064