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

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

parent 98b30d73
...@@ -14,7 +14,7 @@ public class RedisCache { ...@@ -14,7 +14,7 @@ public class RedisCache {
private String cacheName; private String cacheName;
private RedisHelper redisHelper; 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); String value = get(key);
// todo 考虑缓存穿透的问题. // todo 考虑缓存穿透的问题.
if (StringUtils.isNotBlank(value)) { if (StringUtils.isNotBlank(value)) {
...@@ -80,6 +80,15 @@ public class RedisCache { ...@@ -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) { private void delete(String key) {
redisHelper.delete(key); redisHelper.delete(key);
} }
......
...@@ -11,7 +11,6 @@ import com.tanpu.community.util.BizUtils; ...@@ -11,7 +11,6 @@ import com.tanpu.community.util.BizUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -20,7 +19,6 @@ import javax.annotation.Resource; ...@@ -20,7 +19,6 @@ import javax.annotation.Resource;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
......
...@@ -135,8 +135,15 @@ public class RankService { ...@@ -135,8 +135,15 @@ public class RankService {
hotestThemes = themeAnalysDOS.stream() hotestThemes = themeAnalysDOS.stream()
.sorted(Comparator.comparing(ThemeAnalysDO::getScore).reversed()) .sorted(Comparator.comparing(ThemeAnalysDO::getScore).reversed())
.collect(Collectors.toList()); .collect(Collectors.toList());
//落库
// 落库
try {
redisCache.setIfAbsent("logThemeRank","1",15);
rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start)); rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start));
}finally {
redisCache.evict("logThemeRank");
}
} }
......
...@@ -95,7 +95,7 @@ tmpfile: ...@@ -95,7 +95,7 @@ tmpfile:
tanpu: tanpu:
fatools: fatools:
svc: 127.0.0.1:8189 svc: https://testtamper.tanpuyun.com
product: product:
svc: https://testtamper.tanpuyun.com svc: https://testtamper.tanpuyun.com
jifen: jifen:
...@@ -118,7 +118,7 @@ tanpu: ...@@ -118,7 +118,7 @@ tanpu:
#打印SQL语句 #打印SQL语句
logging: logging:
level: level:
com.tanpu.community.dao: debug com.tanpu.community.dao: info
org.springframework.jdbc.core.JdbcTemplate: debug org.springframework.jdbc.core.JdbcTemplate: debug
pagehelper: 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