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.

example.py 702 B

2 years ago
123456789101112131415161718192021222324252627
  1. from source import options, generator, idregister
  2. if __name__ == '__main__':
  3. try:
  4. # 连接redis
  5. register = idregister.Register(host="127.0.0.1", port=6379)
  6. # 获取worker id
  7. worker_id = register.get_worker_id()
  8. # 生成id generator
  9. options = options.IdGeneratorOptions(worker_id=worker_id, seq_bit_length=10)
  10. options.base_time = 12311111112
  11. idgen = generator.DefaultIdGenerator()
  12. idgen.set_id_generator(options)
  13. uid = idgen.next_id()
  14. print(worker_id)
  15. print(uid)
  16. print(options.__dict__)
  17. # 退出注册器线程
  18. register.stop()
  19. except ValueError as e:
  20. print(e)