增加redis缓存防止重复数据

master
YXY 1 year ago
parent 7b0f632c1a
commit e9ca2de5f2

@ -35,6 +35,15 @@ public class RedisCache {
redisTemplate.opsForValue().set(key, value); redisTemplate.opsForValue().set(key, value);
} }
public Boolean setCacheObjectIfAbsent(final String key, String value, Long time, TimeUnit timeUnit) {
try {
return redisTemplate.opsForValue().setIfAbsent(key, value,time,timeUnit);
}catch (Exception e){
}
return true;
}
/** /**
* IntegerString * IntegerString
* *

@ -469,7 +469,8 @@ public abstract class SyncAccountsJobAbstract {
body.put(larkLabel, this.changeValueType(value, cjtSyncTypeRelation)); body.put(larkLabel, this.changeValueType(value, cjtSyncTypeRelation));
} }
uniqueKey = String.join("_", uniqueKeyList).toUpperCase() + "_" + addRecordRequest.getAppTable(); uniqueKey = String.join("_", uniqueKeyList).toUpperCase() + "_" + addRecordRequest.getAppTable();
if (repeatMap.containsKey(uniqueKey)) { Boolean existFlag = redisCache.setCacheObjectIfAbsent(uniqueKey, uniqueKey, 5L, TimeUnit.MINUTES);
if (repeatMap.containsKey(uniqueKey) || !existFlag) {
continue; continue;
} }
repeatMap.put(uniqueKey, 1); repeatMap.put(uniqueKey, 1);

Loading…
Cancel
Save