Commit 136a02c5 authored by hanbing's avatar hanbing

修复 Redis 清理任务

parent 9bb4f53c
...@@ -2,6 +2,7 @@ package net.wanji.datacenter.task; ...@@ -2,6 +2,7 @@ package net.wanji.datacenter.task;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.datacenter.util.RedisUtils; import net.wanji.datacenter.util.RedisUtils;
import org.springframework.data.redis.connection.DataType;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -28,8 +29,10 @@ public class RedisTask { ...@@ -28,8 +29,10 @@ public class RedisTask {
try { try {
Set<String> keys = redisUtils.keys(); Set<String> keys = redisUtils.keys();
for (String key : keys) { for (String key : keys) {
if (redisUtils.keyType(key) == DataType.ZSET) {
redisUtils.removeExpiredElements(key); redisUtils.removeExpiredElements(key);
} }
}
} catch (Exception e) { } catch (Exception e) {
log.error("清理路口事件缓存失败", e); log.error("清理路口事件缓存失败", e);
throw new Exception(e); throw new Exception(e);
......
package net.wanji.datacenter.util; package net.wanji.datacenter.util;
import net.wanji.datacenter.constant.Constant; import net.wanji.datacenter.constant.Constant;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.support.atomic.RedisAtomicLong; import org.springframework.data.redis.support.atomic.RedisAtomicLong;
...@@ -300,6 +301,14 @@ public class RedisUtils { ...@@ -300,6 +301,14 @@ public class RedisUtils {
return redisTemplate.keys("*"); return redisTemplate.keys("*");
} }
/**
* 获取key的类型
* @return
*/
public DataType keyType(String key) {
return redisTemplate.type(key);
}
/** /**
* 获取全局ID范围 * 获取全局ID范围
* *
......
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