pysnowflake的使用

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.使用:

# 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
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值