分布式主键生成器,支持多机器|多进程|多线程并发生成。
Project description
项目描述
分布式主键生成器,支持多机器|多进程|多线程并发生成。
作者
主页 | Github | PyPi | 微信 | 邮箱 | 捐赠
Bug提交、功能提议
你可以通过 Github-Issues、微信 与我联系。
安装
pip install incrementer
教程 (查看美化版 👈)
本文将以简洁的方式向你介绍核心知识,而不会让你被繁琐的术语所淹没。
导入
from incrementer import Incrementer
创建生成器
inc = Incrementer()
创建自增主键
inc.get_incpk() # >>> '1_1'
inc.get_incpk() # >>> '1_2'
inc.get_incpk() # >>> '1_3'
_
左边的 1
表示线程编码。
如果是在单线程情况下使用,可以调用 get_simple_incpk
方法:
inc.get_simple_incpk() # >>> '1'
inc.get_simple_incpk() # >>> '2'
inc.get_simple_incpk() # >>> '3'
get_incpk 同时适用于单线程和多线程情况下,而 get_simple_incpk 仅适用于单线程情况下。
获取编码后的时间戳
inc.get_encoded_time() # >>> 'lwdnayli'
获取编码后的进程ID
inc.encoded_pid # >>> '30g'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
incrementer-1.0.tar.gz
(6.7 kB
view hashes)
Built Distribution
Close
Hashes for incrementer-1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04b4bed675888976c828f92478ef35283339cd9be566797089ec9fde282755ca |
|
MD5 | 9361e157ec618369306e9126b916881e |
|
BLAKE2b-256 | 9709d266d752634dea0ee64129929ffcddaa13dc5227fe8cfbabebd3eee38725 |