gen-uniqueid
v0.0.2
Published
基于雪花算法的自增id生成器
Downloads
3
Readme
简介
基于雪花算法的自增id生成器
const {SnowFlake} = require("gen-uniqueid")
let gen = new SnowFlake({ workerId: process.env.WorkerId == undefined ? 1 : process.env.WorkerId })
let arr = []
for(let i = 0; i < 10; i++){
arr.push(gen.NextId())
}
setTimeout(() => {
for(let i = 0; i < 10; i++){
arr.push(gen.NextId())
}
setTimeout(() => {
for(let i = 0; i < 10; i++){
arr.push(gen.NextId())
}
for(let i=0; i< 29; i++) {
let res = arr[i+1] - arr[i] ? true : false
console.log('大小比较:', res)
}
console.log('全部数据:', arr)
}, 1000)
}, 1000)