public Map<String, List<Catalog2Vo>> getCataLogJson2() {
String cataLogJson = RedisUtils.String2.get("cataLogJson");
if (StringUtils.isEmpty(cataLogJson)) {
return getCataLogJsonFromRedisLock();
}
}
public Map<String, List<Catalog2Vo>> getCataLogJsonFromRedisLock() {
String uuid = UUID.randomUUID().toString();
Boolean lock = RedisUtils.String2.setIfAbsent("lock", uuid, 20);
if (lock) {
Map<String, List<Catalog2Vo>> cataLogJsonFromDB = null;
try {
cataLogJsonFromDB = getCataLogJsonFromDB();
} finally {
String script = "if redis.call('get',KEYS[1]) == ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end";
Long lock1 = RedisUtils.redisTemplate().execute(new DefaultRedisScript<Long>(script, Long.class),Collections.singletonList("lock"), uuid);
}
return cataLogJsonFromDB;
} else {
System.err.println("获取分布式锁------失败");
try {
Thread.sleep(200);
} catch (Exception e) {
}
return getCataLogJsonFromRedisLock();
}
}
|