hengyunabc / redis-id-generator Goto Github PK
View Code? Open in Web Editor NEWdistributed id generator based on redis.
distributed id generator based on redis.
你好,我在demo中添加了所有生成的id放到安全的map key中。最后得到的id数量不正确,说明id重复了。
我的环境是单点redis。可能的原因是什么呢?
下载源码测试,开启500个线程测试会出现偶尔Could not return the resource to the pool异常
local count;
repeat
count = tonumber(redis.call('INCRBY', miliSecondKey, step));
if count > (1024 - step) then
now = redis.call('TIME');
miliSecondKey = prefix .. tag ..'_' .. partition .. '_' .. now[1] .. '_' .. math.floor(now[2]/1000);
end
until count <= (1024 - step)
if count == step then
redis.call('PEXPIRE', miliSecondKey, 5);
end
如上,如果某个毫秒下调用量很大,走进了count > (1024 - step),然后重新计算miliSecondKey,然后还是这个毫秒,然后在下次循环count = tonumber(redis.call('INCRBY', miliSecondKey, step));之前,这个毫秒key被redis后台检查超时超过了5毫秒而删除了,那么这时候count将又回到step,毫秒也是之前的毫秒,这时候不就重复了吗?
集群中三台master负责的插槽是都是某个范围的,你如何保证三个key分布到三台master上。
until count <= (1024 - step)
此处是否应该改为
until count <= (1024 - startStep )
在lua脚本中有一个key做incrby,通过jedis调用,通过keys *命令,这个key并没有设置到redis中,我通过./bin/redis-cli --eval redis-script-node1.lua是有设置这个key的
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.