You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

generator.py 739 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. """
  2. 雪花算法生成器IdGenerator
  3. """
  4. # !/usr/bin/python
  5. # coding=UTF-8
  6. from . import options
  7. from . import snowflake_m1
  8. class DefaultIdGenerator:
  9. """
  10. ID生成器
  11. """
  12. def __init__(self):
  13. self.snowflake = None
  14. def set_id_generator(self, option: options.IdGeneratorOptions):
  15. """
  16. 设置id生成规则信息
  17. """
  18. if option.base_time < 100000:
  19. raise ValueError("base time error.")
  20. self.snowflake = snowflake_m1.SnowFlakeM1(option)
  21. def next_id(self) -> int:
  22. """
  23. 获取新的UUID
  24. """
  25. if self.snowflake is None:
  26. raise ValueError("please set id generator at first.")
  27. return self.snowflake.next_id()