redis文件引起的问题

This commit is contained in:
wanggeng 2024-08-01 16:18:04 +08:00
parent 034750115d
commit 7319c24403

View File

@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* @ClassName: RedisFilesShowCodeServiceImpl
@ -36,12 +37,12 @@ public class RedisFilesShowCodeService implements IFilesShowCodeService {
@Override
public void clearTimeoutShowCode() {
Set<String> keySet = redisTemplate.keys(FILE_SHOW_CODE_KEY);
Set<String> keySet = redisTemplate.keys(FILE_SHOW_CODE_KEY + "**");
long currentTimeMillis = System.currentTimeMillis();
Set<String> clearKeys = new HashSet<>(16);
long clearTimeoutShowCodeCount = 0;
for (String key : keySet) {
FilesShowCode showCode = getShowCode(key);
FilesShowCode showCode = (FilesShowCode) redisTemplate.opsForValue().get(key);
if (currentTimeMillis - showCode.getLatestUpdateTime() > SHOW_CODE_TIMEOUT_MILLIS) {
clearKeys.add(FILE_SHOW_CODE_KEY + showCode.getFileId());
}
@ -66,8 +67,7 @@ public class RedisFilesShowCodeService implements IFilesShowCodeService {
public synchronized FilesShowCode getShowCode(String fileId) {
FilesShowCode showCode = (FilesShowCode) redisTemplate.opsForValue().get(FILE_SHOW_CODE_KEY + fileId);
if (showCode != null) {
showCode.setLatestUpdateTime(System.currentTimeMillis());
redisTemplate.opsForValue().set(FILE_SHOW_CODE_KEY + fileId, showCode);
redisTemplate.opsForValue().set(FILE_SHOW_CODE_KEY + fileId, showCode, 1, TimeUnit.MINUTES);
}
return showCode;
}