Class SnowflakeIdGenerator
java.lang.Object
icu.congee.id.generator.distributed.snowflake.SnowflakeIdGenerator
- All Implemented Interfaces:
IdGenerator
雪花算法ID生成器
64位ID (42位时间戳 + 10位机器ID + 12位序列号)
整体结构: - 符号位:1位,固定为0 - 时间戳:41位,精确到毫秒,可用69年 - 机器ID:10位,最多支持1024个节点 - 序列号:12位,同一毫秒内最多生成4096个ID
-
Constructor Summary
ConstructorsConstructorDescriptionSnowflakeIdGenerator(org.redisson.api.RedissonClient redissonClient, long epoch, int timestampBits, int machineIdBits, int sequenceBits) -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface icu.congee.id.base.IdGenerator
generate
-
Constructor Details
-
SnowflakeIdGenerator
public SnowflakeIdGenerator(org.redisson.api.RedissonClient redissonClient, @Value("${id.generator.snowflake.epoch:1645557742000}") long epoch, @Value("${id.generator.snowflake.timestamp:41}") int timestampBits, @Value("${id.generator.snowflake.machine:10}") int machineIdBits, @Value("${id.generator.snowflake.sequence:12}") int sequenceBits)
-
-
Method Details
-
generate
生成下一个ID- Specified by:
generatein interfaceIdGenerator- Returns:
- 生成的ID
- Throws:
RuntimeException- 当发生时钟回拨时抛出异常
-
idType
获取ID生成器类型- Specified by:
idTypein interfaceIdGenerator- Returns:
- Snowflake类型
-