
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
redis-snowflake-id
Advanced tools
Node.js implementation of Twitter Snowflake ID Generator, base on redis.
Node.js 版本的 Twitter 雪花算法(Snowflake) 发号器。基于 redis 存储发号器自增序号
1.2.0版本开始改用ioredis模块作为redis客户端
npm install redis-snowflake-id -S
或
pnpm add redis-snowflake-id
let options = {
// Redis 客户端配置,配置详见 https://www.npmjs.com/package/ioredis
// 如果不传,可调用buildId方法,手工生成id,详见test.js
redis: {
host: '127.0.0.1',
},
// 世纪,用于减少生成的id数字大小,单位:毫秒,如:1300000000000
epoch: 0,
// redis 的hash键名
hash_key: 'REDIS_SNOWFLAKE_ID',
};
// 创建发号器实例
let idgen = new RedisSnowflakeId(options);
// 生成id
let id = await idgen.next();
console.log('id', id);
// 根据id解析生成的时间戳(毫秒)
let time = idgen.parse(id);
console.log('time', time);
// 生成不同业务类型的id,可选值:0~255,默认:0
let machineId = 3;
let id2 = await idgen.next(machineId);
console.log('id2', id2);
雪花算法(snowflake)是将时间戳、业务id、自增序列分别转为二进制,然后拼接到一起,再转回10进制,得到唯一id。
本项目根据实际情况将时间戳补全到41位,业务id补全到8位,自增序列补全到14位,如果业务id不够用,可自行调整
0 00000000000000000000000000000000000000000 00000000 00000000000000
0 + 41位时间戳 + 8位业务id + 14位自增序列
FAQs
Node.js implementation of Twitter Snowflake ID Generator, base on redis.
We found that redis-snowflake-id demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.