pysnowflakeの使用
1185 ワード
github:https://github.com/koblas/pysnowflake
ドキュメント:https://pysnowflake.readthedocs.io/en/latest/
使用の概要:
1.インストール:pip install pysnowflake
2.端末実行:snowflake_start_server [--dc=DC_ID] [--worker=WORKER_ID] [--host=ADDRESS] [--port=PORT]
またはバックグラウンドで実行:nohup snowflake_start_server --address=127.0.0.1 --port=6001 --dc=1 --worker=1 --log_file_prefix=/tmp/pysnowflask.log>/dev/null &
3.使用:
ドキュメント:https://pysnowflake.readthedocs.io/en/latest/
使用の概要:
1.インストール:pip install pysnowflake
2.端末実行:snowflake_start_server [--dc=DC_ID] [--worker=WORKER_ID] [--host=ADDRESS] [--port=PORT]
またはバックグラウンドで実行:nohup snowflake_start_server --address=127.0.0.1 --port=6001 --dc=1 --worker=1 --log_file_prefix=/tmp/pysnowflask.log>/dev/null &
3.使用:
# just import and use it
import snowflake.client
# One time only initialization
>>> snowflake.client.setup(host, port)
# Then get the ID whenever you need
>>> snowflake.client.get_guid()
3631957913783762945
# See the stats if you want
>>> snowflake.client.get_stats()
{
'dc': 0,
'worker': 0,
'timestamp': 1416207853020, # current timestamp for this worker
'last_timestamp': 1416207845161, # the last timestamp that generated ID on
'sequence': 12, # the sequence number for last timestamp
'sequence_overload': 1, # the number of times that the sequence is overflow
'errors': 1, # the number of times that clock went backward
}