Skip to main content

分布式主键生成器,支持多机器|多进程|多线程并发生成。

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


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)

Uploaded Source

Built Distribution

incrementer-1.0-py2.py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page