Commit a0c1655b authored by 刘基明's avatar 刘基明

多实例记录rank日志添加分布式锁

parent 98b30d73
......@@ -14,7 +14,7 @@ public class RedisCache {
private String cacheName;
private RedisHelper redisHelper;
public<T> T getObject(String key, Integer expireSeconds, Supplier<T> func, Class<T> clz) {
public <T> T getObject(String key, Integer expireSeconds, Supplier<T> func, Class<T> clz) {
String value = get(key);
// todo 考虑缓存穿透的问题.
if (StringUtils.isNotBlank(value)) {
......@@ -80,6 +80,15 @@ public class RedisCache {
}
}
public boolean setIfAbsent(String key, String value, Integer expireSeconds) {
key = cacheName + ":" + key;
if (expireSeconds == 0) {
return redisHelper.setIfAbsent(key, value);
} else {
return redisHelper.setIfAbsent(key, value, Duration.ofSeconds(expireSeconds));
}
}
private void delete(String key) {
redisHelper.delete(key);
}
......
......@@ -11,7 +11,6 @@ import com.tanpu.community.util.BizUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -20,7 +19,6 @@ import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......
......@@ -135,8 +135,15 @@ public class RankService {
hotestThemes = themeAnalysDOS.stream()
.sorted(Comparator.comparing(ThemeAnalysDO::getScore).reversed())
.collect(Collectors.toList());
//落库
// 落库
try {
redisCache.setIfAbsent("logThemeRank","1",15);
rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start));
}finally {
redisCache.evict("logThemeRank");
}
}
......
......@@ -95,7 +95,7 @@ tmpfile:
tanpu:
fatools:
svc: 127.0.0.1:8189
svc: https://testtamper.tanpuyun.com
product:
svc: https://testtamper.tanpuyun.com
jifen:
......@@ -118,7 +118,7 @@ tanpu:
#打印SQL语句
logging:
level:
com.tanpu.community.dao: debug
com.tanpu.community.dao: info
org.springframework.jdbc.core.JdbcTemplate: debug
pagehelper:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment