[求助]雪花算法生成ID缩短
)
workerID
单机,dataCenterID
只有一个,如何调整,41位缩短支持2030年即可,生成后的ID
例如:92235017786232830
越短越好。
41bit timestamp | 10 bit machineID : 5bit workerID 5bit dataCenterID | 12 bit sequenceBits
最多使用69年const ( workerIDBits = uint64(5) // 10bit 工作机器ID中的 5bit workerID dataCenterIDBits = uint64(5) // 10 bit 工作机器ID中的 5bit dataCenterID sequenceBits = uint64(12) maxWorkerID = int64(-1) ^ (int64(-1) << workerIDBits) //节点ID的最大值 用于防止溢出 maxDataCenterID = int64(-1) ^ (int64(-1) << dataCenterIDBits) maxSequence = int64(-1) ^ (int64(-1) << sequenceBits) timeLeft = uint8(22) // timeLeft = workerIDBits + sequenceBits // 时间戳向左偏移量 dataLeft = uint8(17) // dataLeft = dataCenterIDBits + sequenceBits workLeft = uint8(12) // workLeft = sequenceBits // 节点IDx向左偏移量 // 2020-05-20 08:00:00 +0800 CST twepoch = int64(1589923200000) // 常量时间戳(毫秒) )
你的意思是这样?