mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-30 20:33:41 +00:00
添加snowflake的datacenterId和workerId的ID分配策略,利用redis的原子锁特性
This commit is contained in:
@@ -70,6 +70,11 @@ public class IdWorkerInit {
|
||||
*/
|
||||
private String cacheValue;
|
||||
|
||||
/**
|
||||
* serializer
|
||||
*/
|
||||
private StringRedisSerializer serializer = new StringRedisSerializer();
|
||||
|
||||
/**
|
||||
* redisTemplate
|
||||
*/
|
||||
@@ -99,8 +104,6 @@ public class IdWorkerInit {
|
||||
//开始处理
|
||||
boolean result = redisTemplate.execute((RedisCallback<Boolean>) connection -> {
|
||||
try {
|
||||
//实例化解析器
|
||||
StringRedisSerializer serializer = new StringRedisSerializer();
|
||||
//锁定标记
|
||||
boolean lock = false;
|
||||
//循环
|
||||
@@ -154,8 +157,6 @@ public class IdWorkerInit {
|
||||
//开始处理
|
||||
boolean result = redisTemplate.execute((RedisCallback<Boolean>) connection -> {
|
||||
try {
|
||||
//实例化解析器
|
||||
StringRedisSerializer serializer = new StringRedisSerializer();
|
||||
//生成key
|
||||
String key = cacheRedisProperties.getPrefix().concat(SPLIT).concat(CACHE_NAME).concat(SPLIT).concat(Integer.toString(this.datacenterId)).concat(SPLIT).concat(Integer.toString(this.workerId));
|
||||
//如果key不存在就创建(防止特殊情况,缓存丢失掉)
|
||||
|
||||
Reference in New Issue
Block a user