|
|
@ -44,40 +44,42 @@ public class TiktokLikeServiceImpl implements TiktokLikeService { |
|
|
long startTime = System.currentTimeMillis(); |
|
|
long startTime = System.currentTimeMillis(); |
|
|
//拿缓存
|
|
|
//拿缓存
|
|
|
String redisKey = RedisKeyConstant.TIKTOK_USER_LIKE_KEY; |
|
|
String redisKey = RedisKeyConstant.TIKTOK_USER_LIKE_KEY; |
|
|
Cursor<Map.Entry<Object, Object>> like = redisService.getHashScan(redisKey); |
|
|
if(redisService.hasKey(redisKey)){ |
|
|
List<TiktokLike> list = new ArrayList<>(); |
|
|
Cursor<Map.Entry<Object, Object>> like = redisService.getHashScan(redisKey); |
|
|
List<String> keyList = new ArrayList<>(); |
|
|
List<TiktokLike> list = new ArrayList<>(); |
|
|
while (like.hasNext()){ |
|
|
List<String> keyList = new ArrayList<>(); |
|
|
Map.Entry<Object, Object> next = like.next(); |
|
|
while (like.hasNext()){ |
|
|
String key = (String) next.getKey(); |
|
|
Map.Entry<Object, Object> next = like.next(); |
|
|
//分离出 userId,imgId
|
|
|
String key = (String) next.getKey(); |
|
|
String[] split = key.split(":"); |
|
|
//分离出 userId,imgId
|
|
|
String userId = split[0]; |
|
|
String[] split = key.split(":"); |
|
|
Long userLongId = Long.parseLong(userId); |
|
|
String userId = split[0]; |
|
|
String imgId = split[1]; |
|
|
Long userLongId = Long.parseLong(userId); |
|
|
Long imgLongId = Long.parseLong(imgId); |
|
|
String imgId = split[1]; |
|
|
//判断图片是否存在
|
|
|
Long imgLongId = Long.parseLong(imgId); |
|
|
TiktokImg img = tiktokImgMapper.selectById(imgLongId); |
|
|
//判断图片是否存在
|
|
|
if(img == null){ |
|
|
TiktokImg img = tiktokImgMapper.selectById(imgLongId); |
|
|
//不存在则图片Id加入删除列表,遍历完删除
|
|
|
if(img == null){ |
|
|
|
|
|
//不存在则图片Id加入删除列表,遍历完删除
|
|
|
|
|
|
keyList.add(key); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
TiktokLike tiktokLike = new TiktokLike(); |
|
|
|
|
|
tiktokLike.setUserId(userLongId); |
|
|
|
|
|
tiktokLike.setImgId(imgLongId); |
|
|
|
|
|
tiktokLike.setIsShow("1"); |
|
|
|
|
|
tiktokLike.setSort(0); |
|
|
|
|
|
tiktokLike.setCreateTime(new Date()); |
|
|
|
|
|
tiktokLike.setUpdateTime(new Date()); |
|
|
|
|
|
list.add(tiktokLike); |
|
|
keyList.add(key); |
|
|
keyList.add(key); |
|
|
continue; |
|
|
|
|
|
} |
|
|
} |
|
|
TiktokLike tiktokLike = new TiktokLike(); |
|
|
//数据插入数据库并删除缓存
|
|
|
tiktokLike.setUserId(userLongId); |
|
|
tiktokLikeMapper.insertBatch(list); |
|
|
tiktokLike.setImgId(imgLongId); |
|
|
if(keyList.size() > 0){ |
|
|
tiktokLike.setIsShow("1"); |
|
|
for (String key : keyList) { |
|
|
tiktokLike.setSort(0); |
|
|
redisService.deleteHashKey(redisKey, key); |
|
|
tiktokLike.setCreateTime(new Date()); |
|
|
} |
|
|
tiktokLike.setUpdateTime(new Date()); |
|
|
|
|
|
list.add(tiktokLike); |
|
|
|
|
|
keyList.add(key); |
|
|
|
|
|
} |
|
|
|
|
|
//数据插入数据库并删除缓存
|
|
|
|
|
|
tiktokLikeMapper.insertBatch(list); |
|
|
|
|
|
if(keyList.size() > 0){ |
|
|
|
|
|
for (String key : keyList) { |
|
|
|
|
|
redisService.deleteHashKey(redisKey, key); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
log.info("==============redis同步点赞记录到db数据完成,耗时【{}】毫秒!===============",System.currentTimeMillis() - startTime); |
|
|
log.info("==============redis同步点赞记录到db数据完成,耗时【{}】毫秒!===============",System.currentTimeMillis() - startTime); |
|
|
|