
https://mp.weixin.qq.com/s/FDIEcLcpcaRzjDWTHiMWrghttp://redis.io/commands/evalhttp://redis.io/commands/evalshahttp://redis.io/commands/time
0, 3, 6, 9, 12 ...
1, 4, 7, 10, 13 ...
2, 5, 8, 11, 14 ...
Fri Mar 13 10:00:00 CST 2015 ,它的距1970年的毫秒数是 1426212000000,假定分片ID是53,自增长序列是4,则生成的ID是:5981966696448054276 = 1426212000000 << 22 + 53 << 10 + 4http://redis.io/commands/timesecond, microSecond, partition, seq((second * 1000 + microSecond / 1000) << (12 + 10)) + (shardId << 10) + seq;
https://gitee.com/BigBigFeiFei/redis-distributed-id-generator-starthttps://github.com/BigBigFeiFei/redis-distributed-id-generator-start
<dependency><groupId>io.github.bigbigfeifei</groupId><artifactId>redis-distributed-id-generator-start</artifactId><version>1.0</version></dependency>或<dependency><groupId>io.gitee.bigbigfeifei</groupId><artifactId>redis-distributed-id-generator-start</artifactId><version>1.0</version></dependency>
## 配置需要保证唯一不重复(eqps中的每一的index唯一,一般配置成递增的,队列交换机绑定关系的bean注入都是根据rps的List下标+eqps中index下标注入保证了唯一性)zlf-redis-id-generator:redis:rps:- redis-host: xxxx1redis-port: 6379redis-pass: 12345678- redis-host: xxxx2redis-port: 6379redis-pass: 12345678- redis-host: xxxx3redis-port: 6379redis-pass: 12345678
@EnableZlfRedisId
package xxxx.controller;import com.zlf.dto.GeneratorIdDto;import com.zlf.service.ZlfRedisIdByScripts1Service;import com.zlf.service.ZlfRedisIdByScripts2Service;import com.zlf.service.ZlfRedisIdByScripts3Service;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;public class IdGcontroller {private ZlfRedisIdByScripts1Service zlfRedisIdByScripts1Service;private ZlfRedisIdByScripts2Service zlfRedisIdByScripts2Service;private ZlfRedisIdByScripts3Service zlfRedisIdByScripts3Service;public Long getId1() {GeneratorIdDto dto = new GeneratorIdDto();dto.setApplicationName("t_id1");dto.setTabName("id1");dto.setLength(16);return zlfRedisIdByScripts1Service.generatorIdByLength(dto);}public Long getId2() {GeneratorIdDto dto = new GeneratorIdDto();dto.setApplicationName("t_id2");dto.setTabName("id2");return zlfRedisIdByScripts2Service.generatorId(dto);}public Long getId3() {GeneratorIdDto dto = new GeneratorIdDto();dto.setApplicationName("t_id3");dto.setTabName("id3");return zlfRedisIdByScripts3Service.generatorId(dto);}}
Address already in use: connect
https://blog.csdn.net/qq_24857309/article/details/111477286报错原因:
1、windows系统为了保护本机,限制了其他机器到本机的连接数.
2、TCP/IP 可释放已关闭连接并重用其资源前,必须经过的时间。关闭和释放之间的此时间间隔通称 TIME_WAIT 状态或两倍最大段生命周期(2MSL)状态。此时间期间,重新打开到客户机和服务器的连接的成本少于建立新连接。减少此条目的值允许 TCP/IP 更快地释放已关闭的连接,为新连接提供更多资源。如果运行的应用程序需要快速释放和创建新连接,而且由于 TIME_WAIT 中存在很多连接,导致低吞吐量,则调整此参数。
修改操作系统注册表
1、打开注册表:regedit
2、找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters
3、新建 DWORD值,name:TcpTimedWaitDe,value:30(十进制) ——> 设置为30秒(默认240)
4、新建 DWORD值,name:MaxUserPort,value:65534(十进制) ——> 设置最大连接数65534
注意:修改时先选择十进制,再填写数字。
5、重启系统
所以需要将注册表的TcpTimedWaitDe、MaxUserPort值修改,本文修改后压缩1000000,一百万线程还是会报这个错的,所以需要将MaxUserPort在改大一点。
原文作者:Java大飞哥;如有侵权,请联系管理员删除。