|
|
|
@@ -4,9 +4,13 @@ import com.iformall.service.RedisService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.dao.DataAccessException; |
|
|
|
import org.springframework.data.redis.core.RedisOperations; |
|
|
|
import org.springframework.data.redis.core.SessionCallback; |
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
@@ -18,28 +22,25 @@ public class RedisServiceImpl implements RedisService { |
|
|
|
private StringRedisTemplate stringRedisTemplate; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Set<Object> hotApi() { |
|
|
|
public Collection<Object> hotApi() { |
|
|
|
return stringRedisTemplate.opsForHash().keys(KEY_HOT_API); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean delRedisKey(List<String> keys) { |
|
|
|
public boolean delRedisKey(Collection<Object> keys) { |
|
|
|
if (CollectionUtils.isEmpty(keys)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
boolean result; |
|
|
|
stringRedisTemplate.multi(); |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForValue().getOperations().delete(keys); |
|
|
|
stringRedisTemplate.opsForHash().delete(KEY_HOT_API, keys.toArray()); |
|
|
|
result = true; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("delRedisKey error", e); |
|
|
|
stringRedisTemplate.discard(); |
|
|
|
result = false; |
|
|
|
} finally { |
|
|
|
stringRedisTemplate.exec(); |
|
|
|
} |
|
|
|
boolean result = stringRedisTemplate.execute(new SessionCallback<Boolean>() { |
|
|
|
@Override |
|
|
|
public Boolean execute(RedisOperations redisOperations) throws DataAccessException { |
|
|
|
redisOperations.multi(); |
|
|
|
redisOperations.opsForValue().getOperations().delete(keys); |
|
|
|
redisOperations.opsForHash().delete(KEY_HOT_API, keys.toArray()); |
|
|
|
redisOperations.exec(); |
|
|
|
return true ; |
|
|
|
} |
|
|
|
}); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |